diff --git a/your-code/challenges.ipynb b/your-code/challenges.ipynb index ba91b3f..76ee837 100644 --- a/your-code/challenges.ipynb +++ b/your-code/challenges.ipynb @@ -13,11 +13,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup = (\"I\",)" ] }, { @@ -31,11 +31,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# Your code here" + "tup = (\"I\",)\n", + "print(type(tup))" ] }, { @@ -53,16 +62,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 87, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n", - "\n", - "# Your explanation here\n", - "# You can :) " + "tup = (\"I\",)\n", + "tup = tup + (\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "print(tup)\n", + "# We cannot modify a tuple, but we can add content to it creating a new tuple. " ] }, { @@ -80,11 +97,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here" + "tup = ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", + "print(tup)\n" ] }, { @@ -102,11 +128,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n')\n", + "('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here" + "tup = ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", + "tup1 = tup[:4]\n", + "tup2 = tup[-4:]\n", + "print(tup1)\n", + "print(tup2)" ] }, { @@ -120,11 +159,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 90, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here" + "tup3 = tup1 + tup2\n", + "print(tup3)" ] }, { @@ -136,11 +184,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 91, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "8\n" + ] + } + ], "source": [ - "# Your code here" + "tup1 = ('I', 'r', 'o', 'n')\n", + "tup2 = ('h', 'a', 'c', 'k')\n", + "number_elements = len(tup1) + len(tup2)\n", + "print(number_elements)\n", + "print(len(tup3))" ] }, { @@ -152,11 +213,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 92, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "tup3 = ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", + "index_h = tup3.index(\"h\")\n", + "index_h" ] }, { @@ -176,20 +250,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "False\n", + "False\n" + ] + } + ], "source": [ - "# Your code here" + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "tup3 = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "\n", + "for letter in letters:\n", + " if letter in tup3:\n", + " print(True)\n", + " else:\n", + " print(False)" ] }, { @@ -203,11 +287,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 94, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Letter a appear 1 times in tup3.\n", + "Letter b appear 0 times in tup3.\n", + "Letter c appear 1 times in tup3.\n", + "Letter d appear 0 times in tup3.\n", + "Letter e appear 0 times in tup3.\n" + ] + } + ], "source": [ - "# Your code here" + "tup3 = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "\n", + "for letter in letters:\n", + " count = tup3.count(letter)\n", + " print(f\"Letter {letter} appear {count} times in tup3.\")" ] }, { @@ -223,7 +323,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 95, "metadata": {}, "outputs": [], "source": [ @@ -248,11 +348,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 96, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[90, 4, 70, 39, 76, 50, 64, 19, 27, 78, 65, 54, 80, 46, 3, 5, 10, 40, 91, 73, 17, 58, 13, 88, 97, 83, 0, 20, 29, 67, 43, 75, 99, 9, 49, 68, 100, 41, 21, 12, 92, 42, 16, 34, 23, 72, 53, 95, 57, 48, 37, 74, 45, 14, 87, 26, 63, 11, 51, 59, 31, 69, 2, 77, 96, 18, 24, 66, 22, 89, 44, 62, 1, 25, 47, 32, 85, 30, 35, 6]\n" + ] + } + ], "source": [ - "# Your code here" + "sample_list_1 = random.sample(range(101), 80)\n", + "print(sample_list_1)" ] }, { @@ -264,11 +373,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n" + ] + } + ], "source": [ - "# your code here" + "set1 = set(sample_list_1)\n", + "print(len(set1))" ] }, { @@ -287,11 +405,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 98, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[88, 95, 32, 32, 80, 70, 61, 81, 90, 47, 75, 24, 17, 33, 74, 75, 2, 56, 63, 79, 22, 14, 55, 24, 11, 19, 90, 63, 59, 58, 12, 46, 87, 24, 84, 69, 34, 76, 95, 62, 95, 26, 77, 18, 52, 66, 36, 99, 5, 6, 5, 16, 2, 15, 66, 26, 47, 93, 52, 78, 71, 33, 85, 26, 56, 93, 64, 1, 66, 46, 7, 53, 80, 36, 70, 56, 85, 23, 41, 50]\n" + ] + } + ], "source": [ - "# your code here" + "import random\n", + "\n", + "sample_list_2 = [random.randint(0, 100) for _ in range(80)]\n", + "print(sample_list_2)" ] }, { @@ -303,11 +432,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 99, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "55\n" + ] + } + ], "source": [ - "# Your code here" + "set2 = set(sample_list_2)\n", + "print(len(set2))\n", + "\n", + "# the length changes because sets removes duplicated numbers." ] }, { @@ -319,11 +459,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 100, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 3, 4, 9, 10, 13, 20, 21, 25, 27, 29, 30, 31, 35, 37, 39, 40, 42, 43, 44, 45, 48, 49, 51, 54, 57, 65, 67, 68, 72, 73, 83, 89, 91, 92, 96, 97, 100}\n" + ] + } + ], "source": [ - "# Your code here" + "set3 = set1 - set2\n", + "print(set3)" ] }, { @@ -335,11 +484,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 101, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{33, 36, 7, 71, 15, 79, 81, 52, 84, 93, 55, 56, 61}\n" + ] + } + ], "source": [ - "# Your code here" + "set4 = set2 - set1\n", + "print(set4)" ] }, { @@ -351,11 +509,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 114, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 2, 5, 6, 11, 12, 14, 16, 17, 18, 19, 22, 23, 24, 26, 32, 34, 41, 46, 47, 50, 53, 58, 59, 62, 63, 64, 66, 69, 70, 74, 75, 76, 77, 78, 80, 85, 87, 88, 90, 95, 99}\n" + ] + } + ], "source": [ - "# Your code here" + "set5 = set1 & set2\n", + "print(set5)" ] }, { @@ -364,7 +531,7 @@ "source": [ "#### What is the relationship among the following values:\n", "\n", - "* len(set1)\n", + "* len(set1) \n", "* len(set2)\n", "* len(set3)\n", "* len(set4)\n", @@ -373,13 +540,49 @@ "Use a math formular to represent that relationship. Test your formular with Python code." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "len(set1) = len(set3) + len(set5)\n", + "len(set2) = len(set4) + len(set5)\n", + "len(set5) = len(set1) U len(set2)\n" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 116, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "len(set1): 80\n", + "len(set2): 55\n", + "len(set3): 38\n", + "len(set4): 13\n", + "len(set5): 42\n", + "len(set1 ∪ set2): 93\n" + ] + } + ], "source": [ - "# Your code here" + "# I had to use chatgpt for this one\n", + "\n", + "assert len(set1) == len(set3) + len(set5), \"Error in formula for set1\"\n", + "assert len(set2) == len(set4) + len(set5), \"Error in formula for set2\"\n", + "\n", + "set_union = set1 | set2\n", + "\n", + "assert len(set_union) == len(set1) + len(set2) - len(set5), \"Error in formula for union\"\n", + "\n", + "print(f\"len(set1): {len(set1)}\")\n", + "print(f\"len(set2): {len(set2)}\")\n", + "print(f\"len(set3): {len(set3)}\")\n", + "print(f\"len(set4): {len(set4)}\")\n", + "print(f\"len(set5): {len(set5)}\")\n", + "print(f\"len(set1 ∪ set2): {len(set_union)}\")" ] }, { @@ -391,11 +594,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 104, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "set6 = []" ] }, { @@ -407,11 +610,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 117, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 34, 35, 37, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 53, 54, 57, 58, 59, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 80, 83, 85, 87, 88, 89, 90, 91, 92, 95, 96, 97, 99, 100}\n" + ] + } + ], "source": [ - "# Your code here" + "set6 = set()\n", + "set6.update(set3, set5)\n", + "print(set6)" ] }, { @@ -423,11 +636,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 118, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 118, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "equal = set1 == set6\n", + "equal" ] }, { @@ -439,11 +664,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 119, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 119, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set1.issubset(set2)" + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 120, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "set1.issubset(set3)" ] }, { @@ -457,11 +713,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 124, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Are the aggregated sets equal? True\n" + ] + } + ], "source": [ - "# Your code here" + "\n", + "\n", + "aggregated_1 = set3.union(set4, set5)\n", + "aggregated_2 = set1.union(set2)\n", + "\n", + "are_aggregated_equal = aggregated_1 == aggregated_2\n", + "\n", + "print(\"Are the aggregated sets equal?\", are_aggregated_equal)" ] }, { @@ -473,11 +744,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 126, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Removed element: 1\n", + "Updated set1: {2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 34, 35, 37, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 53, 54, 57, 58, 59, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 80, 83, 85, 87, 88, 89, 90, 91, 92, 95, 96, 97, 99, 100}\n" + ] + } + ], "source": [ - "# Your code here" + "rem_element = set1.pop()\n", + "\n", + "print(\"Removed element:\", rem_element)\n", + "print(\"Updated set1:\", set1)" ] }, { @@ -493,11 +776,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 127, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Remaining elements in set1: {2, 3, 4, 5, 6, 10, 12, 13, 14, 16, 17, 18, 20, 22, 23, 24, 25, 26, 27, 30, 32, 34, 35, 37, 40, 42, 43, 44, 45, 46, 47, 48, 50, 53, 54, 57, 58, 62, 63, 64, 65, 66, 67, 68, 70, 72, 73, 74, 75, 76, 77, 78, 80, 83, 85, 87, 88, 90, 92, 95, 96, 97, 100}\n" + ] + } + ], "source": [ - "# Your code here" + "list_to_remove = [1, 9, 11, 19, 21, 29, 31, 39, 41, 49, 51, 59, 61, 69, 71, 79, 81, 89, 91, 99]\n", + "for item in list_to_remove:\n", + " set1.discard(item)\n", + "\n", + "print(\"Remaining elements in set1:\", set1)" ] }, { @@ -515,7 +810,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 111, "metadata": {}, "outputs": [], "source": [ @@ -551,11 +846,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 128, "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" + "word_freq = {'love': 25, 'conversation': 1, 'every': 6, \"we're\": 1, 'plate': 1, 'sour': 1, 'jukebox': 1, 'now': 11, 'taxi': 1, 'fast': 1, 'bag': 1, 'man': 1, 'push': 3, 'baby': 14, 'going': 1, 'you': 16, \"don't\": 2, 'one': 1, 'mind': 2, 'backseat': 1, 'friends': 1, 'then': 3, 'know': 2, 'take': 1, 'play': 1, 'okay': 1, 'so': 2, 'begin': 1, 'start': 2, 'over': 1, 'body': 17, 'boy': 2, 'just': 1, 'we': 7, 'are': 1, 'girl': 2, 'tell': 1, 'singing': 2, 'drinking': 1, 'put': 3, 'our': 1, 'where': 1, \"i'll\": 1, 'all': 1, \"isn't\": 1, 'make': 1, 'lover': 1, 'get': 1, 'radio': 1, 'give': 1, \"i'm\": 23, 'like': 10, 'can': 1, 'doing': 2, 'with': 22, 'club': 1, 'come': 37, 'it': 1, 'somebody': 2, 'handmade': 2, 'out': 1, 'new': 6, 'room': 3, 'chance': 1, 'follow': 6, 'in': 27, 'may': 2, 'brand': 6, 'that': 2, 'magnet': 3, 'up': 3, 'first': 1, 'and': 23, 'pull': 3, 'of': 6, 'table': 1, 'much': 2, 'last': 3, 'i': 6, 'thrifty': 1, 'grab': 2, 'was': 2, 'driver': 1, 'slow': 1, 'dance': 1, 'the': 18, 'say': 2, 'trust': 1, 'family': 1, 'week': 1, 'date': 1, 'me': 10, 'do': 3, 'waist': 2, 'smell': 3, 'day': 6, 'although': 3, 'your': 21, 'leave': 1, 'want': 2, \"let's\": 2, 'lead': 6, 'at': 1, 'hand': 1, 'how': 1, 'talk': 4, 'not': 2, 'eat': 1, 'falling': 3, 'about': 1, 'story': 1, 'sweet': 1, 'best': 1, 'crazy': 2, 'let': 1, 'too': 5, 'van': 1, 'shots': 1, 'go': 2, 'to': 2, 'a': 8, 'my': 33, 'is': 5, 'place': 1, 'find': 1, 'shape': 6, 'on': 40, 'kiss': 1, 'were': 3, 'night': 3, 'heart': 3, 'for': 3, 'discovering': 6, 'something': 6, 'be': 16, 'bedsheets': 3, 'fill': 2, 'hours': 2, 'stop': 1, 'bar': 1}\n", + "\n", + "keys = list(word_freq.keys())\n", + "keys.sort()\n", + "word_freq2 = {}\n", + "for key in keys:\n", + " word_freq2[key] = word_freq[key]\n", + " \n", + "print(word_freq2)" ] }, { @@ -592,17 +903,34 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 129, + "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": [ - "# Your code here" + "import operator\n", + "\n", + "word_freq = {'love': 25, 'conversation': 1, 'every': 6, \"we're\": 1, 'plate': 1, 'sour': 1, 'jukebox': 1, 'now': 11, 'taxi': 1, 'fast': 1, 'bag': 1, 'man': 1, 'push': 3, 'baby': 14, 'going': 1, 'you': 16, \"don't\": 2, 'one': 1, 'mind': 2, 'backseat': 1, 'friends': 1, 'then': 3, 'know': 2, 'take': 1, 'play': 1, 'okay': 1, 'so': 2, 'begin': 1, 'start': 2, 'over': 1, 'body': 17, 'boy': 2, 'just': 1, 'we': 7, 'are': 1, 'girl': 2, 'tell': 1, 'singing': 2, 'drinking': 1, 'put': 3, 'our': 1, 'where': 1, \"i'll\": 1, 'all': 1, \"isn't\": 1, 'make': 1, 'lover': 1, 'get': 1, 'radio': 1, 'give': 1, \"i'm\": 23, 'like': 10, 'can': 1, 'doing': 2, 'with': 22, 'club': 1, 'come': 37, 'it': 1, 'somebody': 2, 'handmade': 2, 'out': 1, 'new': 6, 'room': 3, 'chance': 1, 'follow': 6, 'in': 27, 'may': 2, 'brand': 6, 'that': 2, 'magnet': 3, 'up': 3, 'first': 1, 'and': 23, 'pull': 3, 'of': 6, 'table': 1, 'much': 2, 'last': 3, 'i': 6, 'thrifty': 1, 'grab': 2, 'was': 2, 'driver': 1, 'slow': 1, 'dance': 1, 'the': 18, 'say': 2, 'trust': 1, 'family': 1, 'week': 1, 'date': 1, 'me': 10, 'do': 3, 'waist': 2, 'smell': 3, 'day': 6, 'although': 3, 'your': 21, 'leave': 1, 'want': 2, \"let's\": 2, 'lead': 6, 'at': 1, 'hand': 1, 'how': 1, 'talk': 4, 'not': 2, 'eat': 1, 'falling': 3, 'about': 1, 'story': 1, 'sweet': 1, 'best': 1, 'crazy': 2, 'let': 1, 'too': 5, 'van': 1, 'shots': 1, 'go': 2, 'to': 2, 'a': 8, 'my': 33, 'is': 5, 'place': 1, 'find': 1, 'shape': 6, 'on': 40, 'kiss': 1, 'were': 3, 'night': 3, 'heart': 3, 'for': 3, 'discovering': 6, 'something': 6, 'be': 16, 'bedsheets': 3, 'fill': 2, 'hours': 2, 'stop': 1, 'bar': 1}\n", + "sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))\n", + "word_freq2 = {}\n", + "\n", + "for key, value in sorted_tups:\n", + " word_freq2[key] = value\n", + "\n", + "print(word_freq2)" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -616,12 +944,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } + "version": "3.13.0" } }, "nbformat": 4,