diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..a1c11d8 Binary files /dev/null and b/.DS_Store differ diff --git a/your-code/challenges.ipynb b/your-code/challenges.ipynb index ba91b3f..a1383a2 100644 --- a/your-code/challenges.ipynb +++ b/your-code/challenges.ipynb @@ -13,11 +13,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup = ('I',)" ] }, { @@ -31,11 +31,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 78, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "tuple" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "type(tup)" ] }, { @@ -52,17 +63,10 @@ ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], + "cell_type": "markdown", + "metadata": {}, "source": [ - "# Your code here\n", - "\n", - "# Your explanation here\n", - "# You can :) " + "No, because you can't append itens into a tuple" ] }, { @@ -80,11 +84,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")" ] }, { @@ -102,11 +106,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 80, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup1 = tup[:4]\n", + "tup2 = tup[4:]" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n')\n", + "('h', 'a', 'c', 'k')\n" + ] + } + ], + "source": [ + "print(tup1)\n", + "print(tup2)" ] }, { @@ -120,11 +144,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup3 = tup1 + tup2" ] }, { @@ -136,11 +160,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 83, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "4\n" + ] + } + ], + "source": [ + "print(len(tup1))\n", + "print(len(tup2))" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "len(tup1)+len(tup2) == len(tup3)" ] }, { @@ -152,11 +206,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], "source": [ - "# Your code here" + "print(tup3.index('h'))" ] }, { @@ -176,20 +238,54 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 100, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here" + "print(tup3)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 101, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup3 = ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", + "letters = ['a','b','c','d','e']" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "False\n", + "False\n" + ] + } + ], + "source": [ + "for x in letters:\n", + " if x in tup3:\n", + " print(True)\n", + " else:\n", + " print(False)" ] }, { @@ -203,11 +299,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 111, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a 1\n", + "b 0\n", + "c 1\n", + "d 0\n", + "e 0\n" + ] + } + ], "source": [ - "# Your code here" + "tup3 = ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", + "letters = ['a','b','c','d','e']\n", + "\n", + "for y in letters:\n", + " count = tup3.count(y)\n", + " print(y, count)" ] }, { @@ -223,7 +336,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 296, "metadata": {}, "outputs": [], "source": [ @@ -248,11 +361,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 297, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[3700, 1045, 2741, 1287, 6283, 3062, 5420, 3271, 3213, 4551, 6613, 5762, 4397, 6411, 5340, 3152, 6617, 8905, 6742, 8614, 4024, 4048, 3676, 798, 3482, 5750, 4736, 2405, 2061, 4307, 1453, 383, 2146, 1510, 5831, 4863, 9556, 4207, 9668, 5435, 5938, 1638, 1791, 2692, 8629, 6695, 4860, 5895, 1648, 8346, 4100, 6481, 5083, 9761, 1236, 4703, 5851, 1728, 4272, 6952, 9252, 7688, 3465, 7320, 6901, 5414, 3589, 7601, 9611, 9429, 8338, 2376, 6453, 3937, 4998, 9665, 8293, 6172, 8368, 7744]\n" + ] + } + ], "source": [ - "# Your code here" + "sample_list_1 = random.sample(range(10000), k=80)\n", + "print(sample_list_1)" ] }, { @@ -264,11 +386,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 298, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 298, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "set1 = set(sample_list_1)\n", + "print(len(set1))\n", + "len(set1) == 80" ] }, { @@ -287,11 +429,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 299, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[82, 76, 34, 47, 90, 85, 18, 92, 57, 48, 18, 80, 17, 68, 38, 2, 50, 93, 39, 25, 20, 51, 8, 100, 90, 0, 65, 78, 90, 10, 62, 89, 38, 92, 29, 21, 82, 9, 92, 36, 10, 36, 96, 95, 25, 23, 83, 90, 68, 18, 19, 50, 12, 6, 7, 56, 80, 64, 59, 58, 77, 40, 67, 37, 10, 74, 86, 64, 20, 53, 76, 30, 67, 81, 62, 90, 0, 83, 98, 85]\n" + ] + } + ], "source": [ - "# your code here" + "sample_list_2 = [random.randint(0, 100) for _ in range(80)]\n", + "print(sample_list_2)" ] }, { @@ -303,11 +454,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 300, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "55\n" + ] + } + ], "source": [ - "# Your code here" + "set2 = set(sample_list_2)\n", + "print(len(set2))" ] }, { @@ -319,11 +479,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 301, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{4100, 3589, 7688, 2061, 1045, 6172, 9761, 9252, 6695, 7744, 3152, 6742, 3676, 4703, 2146, 8293, 1638, 4207, 1648, 3700, 5750, 4736, 5762, 2692, 6283, 3213, 8338, 7320, 8346, 4272, 8368, 2741, 1728, 3271, 5831, 8905, 4307, 1236, 9429, 5851, 5340, 6901, 4860, 1791, 4863, 1287, 5895, 6411, 798, 5414, 6952, 5420, 4397, 5938, 6453, 5435, 2376, 6481, 9556, 3937, 2405, 383, 4998, 3465, 9611, 3482, 8614, 1453, 7601, 8629, 4024, 9665, 9668, 4551, 4048, 6613, 6617, 5083, 1510, 3062}\n" + ] + } + ], "source": [ - "# Your code here" + "set1 = set(sample_list_1)\n", + "set2 = set(sample_list_2)\n", + "set3 = set1 - set2\n", + "print(set3)" ] }, { @@ -335,11 +506,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 302, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 2, 6, 7, 8, 9, 10, 12, 17, 18, 19, 20, 21, 23, 25, 29, 30, 34, 36, 37, 38, 39, 40, 47, 48, 50, 51, 53, 56, 57, 58, 59, 62, 64, 65, 67, 68, 74, 76, 77, 78, 80, 81, 82, 83, 85, 86, 89, 90, 92, 93, 95, 96, 98, 100}\n" + ] + } + ], "source": [ - "# Your code here" + "set4 = set2 - set1\n", + "print(set4)\n", + " " ] }, { @@ -351,11 +532,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 303, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set()\n" + ] + } + ], "source": [ - "# Your code here" + "set5 = set1 & set2\n", + "print(set5)" ] }, { @@ -375,11 +565,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 304, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n", + "55\n", + "80\n", + "55\n", + "0\n" + ] + } + ], "source": [ - "# Your code here" + "print(len(set1))\n", + "print(len(set2))\n", + "print(len(set3))\n", + "print(len(set4))\n", + "print(len(set5))" ] }, { @@ -391,11 +597,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 305, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set()\n" + ] + } + ], "source": [ - "# Your code here" + "set6 = set()\n", + "print(set6)" ] }, { @@ -407,11 +622,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 306, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{4100, 3589, 1287, 7688, 5895, 6411, 2061, 1045, 6172, 798, 9761, 9252, 5414, 6695, 6952, 5420, 4397, 5938, 6453, 5435, 7744, 2376, 3152, 6481, 9556, 6742, 3676, 4703, 3937, 2146, 8293, 1638, 2405, 4207, 1648, 3700, 5750, 383, 4736, 5762, 2692, 4998, 3465, 6283, 9611, 3213, 8338, 4863, 7320, 8346, 3482, 8614, 1453, 4272, 8368, 7601, 2741, 8629, 4024, 1728, 9665, 9668, 3271, 5831, 8905, 4551, 4048, 4307, 1236, 9429, 6613, 6617, 5851, 5340, 5083, 1510, 6901, 3062, 4860, 1791}\n" + ] + } + ], "source": [ - "# Your code here" + "set6.update(set3)\n", + "set6.update(set5)\n", + "\n", + "print(set6)" ] }, { @@ -423,11 +649,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 307, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 307, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "set1 == set6" ] }, { @@ -439,11 +676,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 308, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n" + ] + } + ], "source": [ - "# Your code here" + "q = set2.issubset(set1)\n", + "w = set3.issubset(set1)\n", + "\n", + "print(q)\n", + "print(w)" ] }, { @@ -457,11 +707,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 309, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 2, 4100, 3589, 6, 7, 7688, 8, 9, 10, 12, 2061, 17, 18, 19, 20, 1045, 21, 23, 25, 6172, 29, 30, 9761, 34, 9252, 36, 37, 6695, 38, 39, 40, 47, 48, 50, 51, 53, 56, 57, 58, 59, 62, 7744, 64, 65, 67, 68, 74, 76, 77, 78, 3152, 80, 81, 82, 83, 85, 6742, 86, 89, 90, 3676, 92, 93, 4703, 95, 96, 2146, 98, 100, 8293, 1638, 4207, 1648, 3700, 5750, 4736, 5762, 2692, 6283, 3213, 8338, 7320, 8346, 4272, 8368, 2741, 1728, 3271, 5831, 8905, 4307, 1236, 9429, 5851, 5340, 6901, 4860, 4863, 1791, 1287, 5895, 6411, 798, 5414, 6952, 5420, 4397, 5938, 6453, 5435, 2376, 6481, 9556, 3937, 2405, 383, 4998, 3465, 9611, 3482, 8614, 1453, 7601, 8629, 4024, 9665, 9668, 4551, 4048, 6613, 6617, 5083, 1510, 3062}\n", + "{0, 2, 4100, 3589, 6, 1287, 7688, 5895, 7, 6411, 8, 2061, 9, 10, 12, 17, 18, 19, 20, 1045, 21, 23, 25, 6172, 29, 798, 30, 9761, 34, 9252, 36, 5414, 6695, 6952, 37, 38, 39, 5420, 4397, 40, 47, 48, 5938, 1791, 50, 6453, 51, 53, 56, 57, 58, 5435, 59, 62, 7744, 64, 65, 67, 68, 2376, 74, 76, 77, 78, 3152, 6481, 80, 81, 9556, 82, 6742, 83, 85, 86, 89, 90, 3676, 92, 93, 4703, 95, 3937, 2146, 96, 98, 8293, 1638, 2405, 100, 4207, 1648, 3700, 5750, 383, 4736, 5762, 2692, 4998, 3465, 6283, 9611, 3213, 8338, 7320, 8346, 3482, 8614, 1453, 4272, 8368, 7601, 2741, 8629, 4024, 1728, 9665, 9668, 3271, 5831, 8905, 4551, 4048, 4307, 1236, 9429, 6613, 6617, 5851, 5340, 5083, 1510, 6901, 3062, 4860, 4863}\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 309, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "set7 = set3.union(set4).union(set5)\n", + "set8 = set1.union(set2)\n", + "print(set7)\n", + "print(set8)\n", + "\n", + "set7 == set8" ] }, { @@ -473,11 +747,74 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 310, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{4100, 3589, 7688, 2061, 1045, 6172, 9761, 9252, 6695, 7744, 3152, 6742, 3676, 4703, 2146, 8293, 1638, 4207, 1648, 3700, 5750, 4736, 5762, 2692, 6283, 3213, 8338, 7320, 8346, 4272, 8368, 2741, 1728, 3271, 5831, 8905, 4307, 1236, 9429, 5851, 5340, 6901, 4860, 4863, 1791, 1287, 5895, 6411, 798, 5414, 6952, 5420, 4397, 5938, 6453, 5435, 2376, 6481, 9556, 3937, 2405, 383, 4998, 3465, 9611, 3482, 8614, 1453, 7601, 8629, 4024, 9665, 9668, 4551, 4048, 6613, 6617, 5083, 1510, 3062}\n" + ] + } + ], + "source": [ + "print(set1)" + ] + }, + { + "cell_type": "code", + "execution_count": 311, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "set_list = list(set1)" + ] + }, + { + "cell_type": "code", + "execution_count": 312, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4100" + ] + }, + "execution_count": 312, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set_list.pop(0)" + ] + }, + { + "cell_type": "code", + "execution_count": 313, + "metadata": {}, + "outputs": [], + "source": [ + "set1 = set(set_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 314, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{3589, 7688, 2061, 1045, 6172, 9761, 9252, 6695, 7744, 3152, 6742, 3676, 4703, 2146, 8293, 1638, 4207, 1648, 3700, 5750, 4736, 5762, 2692, 6283, 3213, 8338, 7320, 8346, 4272, 8368, 2741, 1728, 3271, 5831, 8905, 4307, 1236, 9429, 5851, 5340, 6901, 4860, 1791, 4863, 1287, 5895, 6411, 798, 5414, 6952, 5420, 4397, 5938, 6453, 5435, 2376, 6481, 9556, 3937, 2405, 383, 4998, 3465, 9611, 3482, 8614, 1453, 7601, 8629, 4024, 9665, 9668, 4551, 4048, 6613, 6617, 5083, 1510, 3062}\n" + ] + } + ], + "source": [ + "print(set1)" ] }, { @@ -493,11 +830,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 277, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{4126, 7712, 4646, 5159, 6697, 4655, 3638, 4162, 1095, 9291, 4178, 4692, 7767, 9826, 6245, 624, 2674, 3698, 8824, 5785, 8860, 9885, 4263, 2742, 4794, 6843, 196, 716, 9427, 2778, 3299, 235, 8427, 8436, 8701, 2819, 4868, 3853, 7442, 6418, 6943, 8479, 6956, 3376, 6449, 7479, 4928, 3908, 3917, 4949, 4445, 5989, 9579, 4484, 3973, 8072, 7056, 921, 412, 9116, 7075, 9124, 7589, 8617, 6057, 4010, 1467, 5061, 4037, 1482, 461, 5082, 2543, 1520, 8694, 5116, 1021}\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", + "\n", + "for x in list_to_remove:\n", + " if x in set1:\n", + " set1.remove(x)\n", + "\n", + "print(set1)" ] }, { @@ -515,7 +866,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 278, "metadata": {}, "outputs": [], "source": [ @@ -551,11 +902,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 279, "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" + "keys = list(word_freq.keys())\n", + "keys.sort()\n", + "\n", + "word_freq2 = {}\n", + "\n", + "for key in keys:\n", + " value = word_freq[key]\n", + " word_freq2[key] = value\n", + "\n", + "print(word_freq2)" ] }, { @@ -592,17 +960,99 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 260, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_items([('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)])" + ] + }, + "execution_count": 260, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "word_freq.items()" + ] + }, + { + "cell_type": "code", + "execution_count": 262, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "import operator\n", + "\n", + "sorted_tups = sorted(word_freq.items(), key = operator.itemgetter(1))" + ] + }, + { + "cell_type": "code", + "execution_count": 263, + "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": [ + "print(sorted_tups)" ] + }, + { + "cell_type": "code", + "execution_count": 264, + "metadata": {}, + "outputs": [], + "source": [ + "word_freq2 = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 265, + "metadata": {}, + "outputs": [], + "source": [ + "for key, value in sorted_tups:\n", + " word_freq2[key] = value" + ] + }, + { + "cell_type": "code", + "execution_count": 266, + "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": [ + "print(word_freq2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -616,12 +1066,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } + "version": "3.13.5" } }, "nbformat": 4,