diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 48f6b46..8da682e 100755 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -15,11 +15,11 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup = 'I'," ] }, { @@ -33,11 +33,19 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# Your code here" + "print(type(tup))" ] }, { @@ -55,13 +63,25 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r')\n" + ] + } + ], "source": [ - "# Your code here\n", + "#tup.append('r')\n", + " # It's not possible to append the elements because the 'tuple' object has no attribute 'append'. \n", + " # This means this Class has not a built-in function for self.append() command. It is logical as tuples are wanted to be inmutable.\n", "\n", - "# Your explanation here\n" + "# The correct process to add the elements to 'tup' is to concatenate it with a tuple of the element.\n", + "tup = tup + tuple('r')\n", + "print(tup)" ] }, { @@ -79,13 +99,26 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('o', 'r')\n" + ] + } + ], "source": [ - "# Your code here\n", + "#tup[0] = 'o',\n", + " # As tuples are intended to be inmutable data structures, 'tuples' object does not support item assignment.\n", "\n", - "# Your explanation here\n" + "# Alternative code (but very different from item assignment) could be:\n", + "l_tup = list(tup)\n", + "l_tup[0] = 'o'\n", + "tup = tuple(l_tup)\n", + "print(tup)" ] }, { @@ -103,11 +136,24 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n')\n", + "('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "tup1 = tup[:4]\n", + "tup2 = tup[-4:]\n", + "print(tup1)\n", + "print(tup2)" ] }, { @@ -121,11 +167,22 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k') ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "tup3 = tup1 + tup2\n", + "print(tup3 == tup)\n", + "print(tup3,tup)" ] }, { @@ -137,11 +194,20 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ - "# Your code here\n" + "sum_tups = len(tup1) + len(tup2)\n", + "print(len(tup3) == sum_tups)" ] }, { @@ -153,11 +219,22 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "tup3.index('h')" ] }, { @@ -177,11 +254,26 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 9, "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 let in letters:\n", + " print(let in tup3,)" ] }, { @@ -195,11 +287,28 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 10, "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 let in letters:\n", + " counter = 0\n", + " for i in range(len(tup3)):\n", + " if let == tup3[i]:\n", + " counter = counter+1\n", + " print(counter)" ] }, { @@ -211,11 +320,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'p_tup1' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mpacked_l\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mpacked_tup\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtuple\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpacked_l\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[1;33m(\u001b[0m\u001b[0mp_tup1\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0mp_tup2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mp_tup3\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m21\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpacked_tup\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 6\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mt\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mp_tup2\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mt\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mNameError\u001b[0m: name 'p_tup1' is not defined" + ] + } + ], "source": [ - "# Your code here\n" + "packed_l = []\n", + "for i in range(100):\n", + " packed_l.append(i)\n", + "packed_tup = tuple(packed_l)\n", + "(p_tup1[:10], *p_tup2, p_tup3[21:]) = packed_tup\n", + "for t in p_tup2:\n", + " print(t)" ] } ], @@ -235,7 +362,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.3" } }, "nbformat": 4, diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index ef7bde3..1b3234e 100755 --- 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": [ @@ -38,11 +38,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[18, 63, 37, 77, 67, 69, 86, 11, 5, 74, 45, 35, 66, 94, 49, 6, 59, 62, 19, 10, 31, 29, 73, 2, 33, 93, 15, 84, 57, 61, 53, 32, 64, 71, 0, 99, 7, 41, 80, 17, 46, 14, 82, 87, 92, 40, 48, 70, 44, 3, 9, 76, 36, 50, 16, 51, 83, 60, 39, 30, 89, 68, 22, 98, 56, 28, 27, 20, 8, 75, 79, 72, 26, 96, 52, 47, 81, 91, 55, 97]\n" + ] + } + ], "source": [ - "# Your code here\n" + "sample_list_1 = random.sample(range(100),80)\n", + "print(sample_list_1)" ] }, { @@ -54,11 +63,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n" + ] + } + ], "source": [ - "# Your code here\n" + "set1 = set(sample_list_1)\n", + "print(len(set1))" ] }, { @@ -77,11 +95,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[9, 27, 21, 46, 13, 98, 55, 41, 7, 93, 61, 61, 73, 45, 9, 58, 32, 9, 83, 37, 10, 77, 72, 98, 89, 9, 38, 56, 72, 1, 12, 96, 33, 76, 97, 74, 18, 77, 69, 79, 50, 33, 26, 20, 25, 8, 72, 3, 46, 9, 76, 87, 39, 71, 78, 99, 80, 7, 42, 78, 76, 0, 99, 68, 77, 37, 15, 42, 75, 47, 10, 46, 78, 47, 21, 65, 77, 30, 51, 24]\n" + ] + } + ], "source": [ - "# Your code here\n" + "sample_list_2 = []\n", + "for i in range(80):\n", + " sample_list_2.append(random.randrange(100))\n", + "print(sample_list_2)" ] }, { @@ -93,11 +122,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "55\n" + ] + } + ], "source": [ - "# Your code here\n" + "set2 = set(sample_list_2)\n", + "print(len(set2))" ] }, { @@ -109,11 +147,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{2, 5, 6, 11, 14, 16, 17, 19, 22, 28, 29, 31, 35, 36, 40, 44, 48, 49, 52, 53, 57, 59, 60, 62, 63, 64, 66, 67, 70, 81, 82, 84, 86, 91, 92, 94}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set3 = set()\n", + "for elem in set1:\n", + " if elem not in set2:\n", + " set3.add(elem)\n", + "print(set3)" ] }, { @@ -125,11 +175,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 65, 38, 42, 12, 13, 78, 21, 24, 25, 58}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set4 = set()\n", + "for elem in set2:\n", + " if elem not in set1:\n", + " set4.add(elem)\n", + "print(set4)" ] }, { @@ -141,11 +203,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 3, 7, 8, 9, 10, 15, 18, 20, 26, 27, 30, 32, 33, 37, 39, 41, 45, 46, 47, 50, 51, 55, 56, 61, 68, 69, 71, 72, 73, 74, 75, 76, 77, 79, 80, 83, 87, 89, 93, 96, 97, 98, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set5 = set()\n", + "for elem in set2:\n", + " if elem in set1:\n", + " set5.add(elem)\n", + "print(set5)" ] }, { @@ -165,11 +239,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80 55 36 11 44\n" + ] + } + ], + "source": [ + "print(len(set1),len(set2),len(set3),len(set4),len(set5))\n", + "\n", + "# len(set3) + len(set5) == len(set1)\n", + "# len(set4) + len(set5) == len(set2)" ] }, { @@ -181,11 +266,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "set6 = set()" ] }, { @@ -197,11 +282,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 2, 3, 5, 6, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 19, 20, 22, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40, 41, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 55, 56, 57, 59, 60, 61, 62, 63, 64, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 86, 87, 89, 91, 92, 93, 94, 96, 97, 98, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set6.update(set3,set5)\n", + "print(set6)" ] }, { @@ -213,11 +307,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ - "# Your code here\n" + "print(set1 == set6)" ] }, { @@ -229,11 +331,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n" + ] + } + ], "source": [ - "# Your code here\n" + "print(set2.issubset(set1))\n", + "print(set1.issuperset(set3))" ] }, { @@ -247,11 +359,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ - "# Your code here\n" + "u_set1 = set3.union(set4,set5)\n", + "u_set2 = set1.union(set2)\n", + "print(u_set1 == u_set2)" ] }, { @@ -263,11 +385,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set1.pop()" ] }, { @@ -283,11 +416,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{2, 3, 5, 6, 7, 8, 10, 14, 15, 16, 17, 18, 20, 22, 26, 27, 28, 30, 32, 33, 35, 36, 37, 40, 44, 45, 46, 47, 48, 50, 52, 53, 55, 56, 57, 60, 62, 63, 64, 66, 67, 68, 70, 72, 73, 74, 75, 76, 77, 80, 82, 83, 84, 86, 87, 92, 93, 94, 96, 97, 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 elem in list_to_remove:\n", + " if elem in set1:\n", + " set1.remove(elem)\n", + "print(set1)" ] } ], @@ -307,7 +453,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.3" } }, "nbformat": 4, diff --git a/your-code/challenge-3.ipynb b/your-code/challenge-3.ipynb index 74d65e0..5b8672e 100755 --- a/your-code/challenge-3.ipynb +++ b/your-code/challenge-3.ipynb @@ -21,11 +21,11 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "dict1 = {'Penelope':178, 'Arnau':172, 'Marta':175}" ] }, { @@ -37,11 +37,23 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict_keys(['Penelope', 'Arnau', 'Marta'])\n", + "dict_values([178, 172, 175])\n", + "dict_items([('Penelope', 178), ('Arnau', 172), ('Marta', 175)])\n" + ] + } + ], "source": [ - "# Your code here\n" + "print(dict1.keys())\n", + "print(dict1.values())\n", + "print(dict1.items())" ] }, { @@ -53,11 +65,20 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175, 'Roberto': 180}\n" + ] + } + ], "source": [ - "# Your code here\n" + "dict1['Roberto'] = 180\n", + "print(dict1)" ] }, { @@ -69,11 +90,20 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175}\n" + ] + } + ], "source": [ - "# Your code here\n" + "del dict1['Roberto']\n", + "print(dict1)" ] }, { @@ -87,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -121,11 +151,24 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 6, "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", + "word_freq2 = {}\n", + "for k in keys:\n", + " word_freq2[k] = word_freq[k]\n", + "print(word_freq2)" ] }, { @@ -162,11 +205,24 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "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", + "word_freq3 = {}\n", + "for t in sorted_tups:\n", + " word_freq3[t[0]] = t[1]\n", + "print(word_freq3)" ] } ], @@ -186,7 +242,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.3" } }, "nbformat": 4,