diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 3ff7f9b..196fe6e 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -14,11 +14,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 96, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "tup = (\"I\", )\n" ] }, { @@ -32,11 +32,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# Your code here\n" + "print (type(tup))\n" ] }, { @@ -54,13 +62,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n", + "new_list = [\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\"]\n", "\n", - "# Your explanation here\n" + "tup_list = list(tup)\n", + "\n", + "tup_list.extend(new_list)\n", + "\n", + "tup = tuple(tup_list)\n", + "\n", + "print (tup)" ] }, { @@ -80,13 +102,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 105, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n", + "new_list2 = [\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\"]\n", + "tup = (\"I\", )\n", "\n", - "# Your explanation here\n" + "tup_list = list(tup)\n", + "\n", + "tup_list.extend(new_list2[1:])\n", + "\n", + "tup = tuple(tup_list)\n", + "\n", + "print (tup)\n", + "\n" ] }, { @@ -104,11 +142,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 93, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n')\n", + "('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "tup1 = tup[0:4]\n", + "tup2 = tup[-4:]\n", + "\n", + "print (tup1)\n", + "print (tup2)" ] }, { @@ -122,11 +173,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 103, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", + "tup3 is equal to tup\n" + ] + } + ], "source": [ - "# Your code here\n" + "tup3 = tup1 + tup2\n", + "print (tup3)\n", + "\n", + "if tup3 == tup:\n", + " print (\"tup3 is equal to tup\") \n", + "else:\n", + " print (\"tup3 is not equal to tup\") " ] }, { @@ -138,11 +204,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 108, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "4\n", + "Total count is equal to tup3\n" + ] + } + ], "source": [ - "# Your code here\n" + "count1 = len(tup1)\n", + "count2 = len(tup2)\n", + "\n", + "total_count = count1 + count2 \n", + "\n", + "\n", + "if total_count == len(tup3): \n", + " print (\"Total count is equal to tup3\")\n", + "else: \n", + " print (\"Total count is not equal to tup3\") \n", + " " ] }, { @@ -154,11 +240,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 109, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 109, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "tup3.index(\"h\")" ] }, { @@ -178,11 +275,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 113, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "False\n", + "False\n" + ] + } + ], "source": [ - "# Your code here\n" + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "\n", + "for i in letters: \n", + " if i in tup3: \n", + " print (\"True\")\n", + " else: \n", + " print (\"False\")\n", + " \n", + " \n", + " " ] }, { @@ -203,12 +321,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 118, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "0\n", + "1\n", + "0\n", + "0\n" + ] + } + ], "source": [ - "# Your code here\n" + "for i in letters:\n", + " print (tup3.count(i))\n", + " \n", + " \n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -227,7 +367,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.11.4" }, "toc": { "base_numbering": 1, diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 49072f2..0ce3098 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -47,11 +47,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[90, 28, 42, 72, 67, 23, 61, 77, 26, 69, 16, 33, 12, 84, 32, 13, 21, 56, 96, 35, 41, 31, 19, 55, 59, 20, 82, 8, 44, 64, 34, 93, 7, 3, 63, 51, 38, 62, 53, 71, 87, 99, 1, 57, 83, 88, 22, 54, 40, 30, 29, 18, 98, 2, 58, 68, 27, 24, 25, 14, 73, 17, 0, 66, 4, 75, 76, 36, 65, 45, 11, 78, 91, 60, 85, 79, 46, 49, 15, 6]\n" + ] + } + ], "source": [ - "# Your code here\n" + "sample_list_1 = random.sample(range(100), k=80)\n", + "print (sample_list_1)" ] }, { @@ -63,11 +72,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n" + ] + } + ], "source": [ - "# Your code here\n" + "set1 = set(sample_list_1)\n", + "print (len(set1))" ] }, { @@ -86,11 +104,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[18, 37, 97, 11, 28, 41, 24, 78, 32, 23, 75, 7, 67, 89, 83, 35, 48, 37, 67, 90, 71, 45, 66, 44, 60, 15, 90, 19, 41, 70, 99, 94, 53, 49, 55, 81, 60, 67, 8, 87, 24, 12, 90, 18, 17, 25, 40, 28, 48, 2, 7, 6, 37, 27, 68, 23, 17, 90, 88, 47, 33, 27, 61, 11, 4, 5, 4, 60, 11, 62, 19, 73, 77, 38, 82, 49, 38, 2, 46, 80]\n" + ] + } + ], "source": [ - "# Your code here\n" + "sample_list_2 = []\n", + "\n", + "for i in range(80):\n", + " sample_list_2.extend(random.sample(range(100), 1))\n", + " \n", + "print (sample_list_2)" ] }, { @@ -102,11 +133,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "55\n" + ] + } + ], "source": [ - "# Your code here\n" + "set2 = set(sample_list_2)\n", + "print (len(set2))" ] }, { @@ -118,11 +158,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "set3 = set1 - set2\n" ] }, { @@ -134,11 +174,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "set4 = set2 - set1\n" ] }, { @@ -150,11 +190,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "set5 = set1.intersection(set2)\n" ] }, { @@ -186,11 +226,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "len (set5) + len(set4) + len(set3) == len (set1) + len(set2) - len(set5)" ] }, { @@ -202,11 +253,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "set6 = set()" ] }, { @@ -218,11 +269,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "set6.update(set3)\n", + "set6.update(set5)\n", + "\n" ] }, { @@ -234,11 +287,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set1 == set6\n" ] }, { @@ -250,11 +314,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Case 2 is True\n" + ] + } + ], "source": [ - "# Your code here\n" + "if set2.issubset(set1):\n", + " print (\"Case 1 is True\")\n", + "\n", + "if set3.issubset(set1):\n", + " print (\"Case 2 is True\")" ] }, { @@ -268,11 +344,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "big_set1 = set3.union(set4, set5)\n", + "big_set2 = set1.union(set2)\n" ] }, { @@ -284,11 +361,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set1.pop()" ] }, { @@ -304,11 +392,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{2, 3, 4, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18, 20, 22, 23, 24, 25, 26, 27, 28, 30, 32, 33, 34, 35, 36, 38, 40, 42, 44, 45, 46, 53, 54, 55, 56, 57, 58, 60, 62, 63, 64, 65, 66, 67, 68, 72, 73, 75, 76, 77, 78, 82, 83, 84, 85, 87, 88, 90, 93, 96, 98}\n" + ] + } + ], "source": [ - "# Your code here\n" + "list_to_remove = [1, 9, 11, 19, 21, 29, 31, 39, 41, 49, 51, 59, 61, 69, 71, 79, 81, 89, 91, 99]\n", + "\n", + "for i in list_to_remove: \n", + " \n", + " set1.discard(i)\n", + " \n", + "print (set1)" ] } ], @@ -328,7 +430,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.11.4" }, "nbTranslate": { "displayLangs": [ diff --git a/your-code/challenge-3.ipynb b/your-code/challenge-3.ipynb index 0dfb2da..aebc66b 100644 --- a/your-code/challenge-3.ipynb +++ b/your-code/challenge-3.ipynb @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -51,11 +51,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'a': 8, 'about': 1, 'all': 1, 'although': 3, 'and': 23, 'are': 1, 'at': 1, 'baby': 14, 'backseat': 1, 'bag': 1, 'bar': 1, 'be': 16, 'bedsheets': 3, 'begin': 1, 'best': 1, 'body': 17, 'boy': 2, 'brand': 6, 'can': 1, 'chance': 1, 'club': 1, 'come': 37, 'conversation': 1, 'crazy': 2, 'dance': 1, 'date': 1, 'day': 6, 'discovering': 6, 'do': 3, 'doing': 2, \"don't\": 2, 'drinking': 1, 'driver': 1, 'eat': 1, 'every': 6, 'falling': 3, 'family': 1, 'fast': 1, 'fill': 2, 'find': 1, 'first': 1, 'follow': 6, 'for': 3, 'friends': 1, 'get': 1, 'girl': 2, 'give': 1, 'go': 2, 'going': 1, 'grab': 2, 'hand': 1, 'handmade': 2, 'heart': 3, 'hours': 2, 'how': 1, 'i': 6, \"i'll\": 1, \"i'm\": 23, 'in': 27, 'is': 5, \"isn't\": 1, 'it': 1, 'jukebox': 1, 'just': 1, 'kiss': 1, 'know': 2, 'last': 3, 'lead': 6, 'leave': 1, 'let': 1, \"let's\": 2, 'like': 10, 'love': 25, 'lover': 1, 'magnet': 3, 'make': 1, 'man': 1, 'may': 2, 'me': 10, 'mind': 2, 'much': 2, 'my': 33, 'new': 6, 'night': 3, 'not': 2, 'now': 11, 'of': 6, 'okay': 1, 'on': 40, 'one': 1, 'our': 1, 'out': 1, 'over': 1, 'place': 1, 'plate': 1, 'play': 1, 'pull': 3, 'push': 3, 'put': 3, 'radio': 1, 'room': 3, 'say': 2, 'shape': 6, 'shots': 1, 'singing': 2, 'slow': 1, 'smell': 3, 'so': 2, 'somebody': 2, 'something': 6, 'sour': 1, 'start': 2, 'stop': 1, 'story': 1, 'sweet': 1, 'table': 1, 'take': 1, 'talk': 4, 'taxi': 1, 'tell': 1, 'that': 2, 'the': 18, 'then': 3, 'thrifty': 1, 'to': 2, 'too': 5, 'trust': 1, 'up': 3, 'van': 1, 'waist': 2, 'want': 2, 'was': 2, 'we': 7, \"we're\": 1, 'week': 1, 'were': 3, 'where': 1, 'with': 22, 'you': 16, 'your': 21}\n" + ] + } + ], "source": [ - "# Your code here\n" + "keys = list(word_freq.keys())\n", + "keys.sort()\n", + "\n", + "word_freq2 = {}\n", + "\n", + "for i in keys:\n", + " \n", + " word_freq2.update({i : word_freq[i]})\n", + "\n", + "print (word_freq2)" ] }, { @@ -92,12 +109,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'conversation': 1, \"we're\": 1, 'plate': 1, 'sour': 1, 'jukebox': 1, 'taxi': 1, 'fast': 1, 'bag': 1, 'man': 1, 'going': 1, 'one': 1, 'backseat': 1, 'friends': 1, 'take': 1, 'play': 1, 'okay': 1, 'begin': 1, 'over': 1, 'just': 1, 'are': 1, 'tell': 1, 'drinking': 1, 'our': 1, 'where': 1, \"i'll\": 1, 'all': 1, \"isn't\": 1, 'make': 1, 'lover': 1, 'get': 1, 'radio': 1, 'give': 1, 'can': 1, 'club': 1, 'it': 1, 'out': 1, 'chance': 1, 'first': 1, 'table': 1, 'thrifty': 1, 'driver': 1, 'slow': 1, 'dance': 1, 'trust': 1, 'family': 1, 'week': 1, 'date': 1, 'leave': 1, 'at': 1, 'hand': 1, 'how': 1, 'eat': 1, 'about': 1, 'story': 1, 'sweet': 1, 'best': 1, 'let': 1, 'van': 1, 'shots': 1, 'place': 1, 'find': 1, 'kiss': 1, 'stop': 1, 'bar': 1, \"don't\": 2, 'mind': 2, 'know': 2, 'so': 2, 'start': 2, 'boy': 2, 'girl': 2, 'singing': 2, 'doing': 2, 'somebody': 2, 'handmade': 2, 'may': 2, 'that': 2, 'much': 2, 'grab': 2, 'was': 2, 'say': 2, 'waist': 2, 'want': 2, \"let's\": 2, 'not': 2, 'crazy': 2, 'go': 2, 'to': 2, 'fill': 2, 'hours': 2, 'push': 3, 'then': 3, 'put': 3, 'room': 3, 'magnet': 3, 'up': 3, 'pull': 3, 'last': 3, 'do': 3, 'smell': 3, 'although': 3, 'falling': 3, 'were': 3, 'night': 3, 'heart': 3, 'for': 3, 'bedsheets': 3, 'talk': 4, 'too': 5, 'is': 5, 'every': 6, 'new': 6, 'follow': 6, 'brand': 6, 'of': 6, 'i': 6, 'day': 6, 'lead': 6, 'shape': 6, 'discovering': 6, 'something': 6, 'we': 7, 'a': 8, 'like': 10, 'me': 10, 'now': 11, 'baby': 14, 'you': 16, 'be': 16, 'body': 17, 'the': 18, 'your': 21, 'with': 22, \"i'm\": 23, 'and': 23, 'love': 25, 'in': 27, 'my': 33, 'come': 37, 'on': 40}\n" + ] + } + ], "source": [ - "# Your code here\n" + "import operator\n", + "sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))\n", + "\n", + "list_tups = list(sorted_tups)\n", + "\n", + "list_tups = list(sorted_tups)\n", + "\n", + "wordfreq_2 = dict(list_tups)\n", + "print (wordfreq_2) \n", + "\n" ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'conversation': 1, \"we're\": 1, 'plate': 1, 'sour': 1, 'jukebox': 1, 'taxi': 1, 'fast': 1, 'bag': 1, 'man': 1, 'going': 1, 'one': 1, 'backseat': 1, 'friends': 1, 'take': 1, 'play': 1, 'okay': 1, 'begin': 1, 'over': 1, 'just': 1, 'are': 1, 'tell': 1, 'drinking': 1, 'our': 1, 'where': 1, \"i'll\": 1, 'all': 1, \"isn't\": 1, 'make': 1, 'lover': 1, 'get': 1, 'radio': 1, 'give': 1, 'can': 1, 'club': 1, 'it': 1, 'out': 1, 'chance': 1, 'first': 1, 'table': 1, 'thrifty': 1, 'driver': 1, 'slow': 1, 'dance': 1, 'trust': 1, 'family': 1, 'week': 1, 'date': 1, 'leave': 1, 'at': 1, 'hand': 1, 'how': 1, 'eat': 1, 'about': 1, 'story': 1, 'sweet': 1, 'best': 1, 'let': 1, 'van': 1, 'shots': 1, 'place': 1, 'find': 1, 'kiss': 1, 'stop': 1, 'bar': 1, \"don't\": 2, 'mind': 2, 'know': 2, 'so': 2, 'start': 2, 'boy': 2, 'girl': 2, 'singing': 2, 'doing': 2, 'somebody': 2, 'handmade': 2, 'may': 2, 'that': 2, 'much': 2, 'grab': 2, 'was': 2, 'say': 2, 'waist': 2, 'want': 2, \"let's\": 2, 'not': 2, 'crazy': 2, 'go': 2, 'to': 2, 'fill': 2, 'hours': 2, 'push': 3, 'then': 3, 'put': 3, 'room': 3, 'magnet': 3, 'up': 3, 'pull': 3, 'last': 3, 'do': 3, 'smell': 3, 'although': 3, 'falling': 3, 'were': 3, 'night': 3, 'heart': 3, 'for': 3, 'bedsheets': 3, 'talk': 4, 'too': 5, 'is': 5, 'every': 6, 'new': 6, 'follow': 6, 'brand': 6, 'of': 6, 'i': 6, 'day': 6, 'lead': 6, 'shape': 6, 'discovering': 6, 'something': 6, 'we': 7, 'a': 8, 'like': 10, 'me': 10, 'now': 11, 'baby': 14, 'you': 16, 'be': 16, 'body': 17, 'the': 18, 'your': 21, 'with': 22, \"i'm\": 23, 'and': 23, 'love': 25, 'in': 27, 'my': 33, 'come': 37, 'on': 40}\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -116,7 +172,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.11.4" }, "nbTranslate": { "displayLangs": [