From 4063c878f2d323182b1331ba8c65285b13da94c0 Mon Sep 17 00:00:00 2001 From: foscanit Date: Tue, 10 Oct 2023 19:31:40 +0200 Subject: [PATCH] [Claudia Pintos] all done --- your-code/challenge-1.ipynb | 250 +++++++++++++++++++---- your-code/challenge-2.ipynb | 385 ++++++++++++++++++++++++++++++------ your-code/challenge-3.ipynb | 102 +++++++++- 3 files changed, 636 insertions(+), 101 deletions(-) diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 3ff7f9b..e95f5ef 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -14,11 +14,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I',)\n" + ] + } + ], "source": [ - "# Your code here\n" + "tup = (\"I\", )\n", + "print(tup)" ] }, { @@ -32,11 +41,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# Your code here\n" + "print(type(tup))" ] }, { @@ -54,13 +71,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'tuple' object has no attribute 'append'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[6], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m tup\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m\"\u001b[39m,)\n", + "\u001b[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'" + ] + } + ], "source": [ - "# Your code here\n", + "tup.append(\"r\",)\n", "\n", - "# Your explanation here\n" + "# I can't add any of these elements because tuples are immutable, you cannot change them, thus we cannot aply the method 'append' to a tuple.\n" ] }, { @@ -80,13 +109,87 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", + "\n" + ] + } + ], "source": [ - "# Your code here\n", + "tup = (\"I\", )\n", + "list_t = list(tup)\n", "\n", - "# Your explanation here\n" + "list_new = [\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\"]\n", + "list_t.extend(list_new)\n", + "\n", + "tup2 = tuple(list_t)\n", + "print(tup2)\n", + "print(type(tup2))" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], + "source": [ + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "print(tup)\n", + "# I'm not modifying the tuple, but instead creating a new one, that's why it lets me \"re-assign\" the elements to 'tup'." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['I', 'r', 'o', 'n', 'h', 'a', 'c', 'k']\n" + ] + } + ], + "source": [ + "tup_l = list(tup)\n", + "print(tup_l)\n", + "\n", + "# With regard to casting, I can convert a tuple into a list, for example." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'n', 'a', 'c', 'I', 'k', 'r', 'h', 'o'}\n" + ] + } + ], + "source": [ + "tup_2 = set(tup)\n", + "print(tup_2)\n", + "\n", + "# I can also convert a tuple into a set." ] }, { @@ -104,11 +207,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "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", + "print(tup1)\n", + "print(tup2)" ] }, { @@ -122,11 +237,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "tup3 = tup1 + tup2\n", + "print(tup3)" ] }, { @@ -138,11 +262,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "8\n" + ] + } + ], "source": [ - "# Your code here\n" + "count_tup1 = len(tup1)\n", + "count_tup2 = len(tup2)\n", + "print(count_tup1 + count_tup2)\n", + "print(len(tup3))" ] }, { @@ -154,11 +290,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "tup3.index(\"h\")" ] }, { @@ -178,11 +325,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "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", + "tup3 = ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", + "\n", + " \n", + "for letter in letters:\n", + " if letter in tup3:\n", + " print(True)\n", + " else:\n", + " print(False)" ] }, { @@ -203,11 +370,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "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\n" + "for letter in letters:\n", + " if letter in tup3:\n", + " count = tup3.count(letter)\n", + " print(f\"'{letter}': {count}\")\n", + " else:\n", + " print(f\"'{letter}': 0\")" ] } ], @@ -227,7 +411,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..b66ccba 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": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[85, 25, 52, 95, 47, 9, 27, 60, 69, 54, 78, 19, 48, 97, 3, 49, 42, 74, 26, 65, 50, 67, 20, 36, 2, 86, 45, 6, 32, 46, 34, 81, 70, 59, 51, 22, 40, 38, 29, 37, 17, 24, 73, 98, 66, 80, 28, 64, 94, 11, 57, 53, 83, 91, 7, 39, 23, 35, 5, 58, 71, 82, 30, 84, 87, 77, 56, 72, 31, 1, 63, 93, 16, 55, 12, 75, 14, 76, 15, 62]\n" + ] + } + ], "source": [ - "# Your code here\n" + "sample_list_1 = random.sample(range(100), k=80)\n", + "print(sample_list_1)" ] }, { @@ -63,11 +72,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n", + "{1, 2, 3, 5, 6, 7, 9, 11, 12, 14, 15, 16, 17, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 42, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 86, 87, 91, 93, 94, 95, 97, 98}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set1 = set(sample_list_1)\n", + "count_set = len(set1)\n", + "print(count_set)\n", + "print(set1)" ] }, { @@ -86,11 +107,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[75, 55, 42, 51, 61, 26, 63, 36, 77, 14, 49, 81, 20, 2, 71, 92, 32, 94, 38, 48, 88, 65, 96, 23, 55, 99, 26, 3, 31, 99, 33, 26, 76, 47, 80, 43, 71, 23, 18, 85, 18, 33, 31, 53, 5, 20, 0, 25, 57, 30, 28, 99, 3, 17, 96, 60, 81, 33, 58, 49, 88, 44, 23, 12, 53, 4, 2, 32, 1, 62, 82, 13, 83, 27, 5, 21, 72, 86, 14, 55]\n", + "80\n" + ] + } + ], "source": [ - "# Your code here\n" + "sample_list_2 = [random.choice(range(100)) for i in range(80)]\n", + "print(sample_list_2)\n", + "print(len(sample_list_2))" ] }, { @@ -102,11 +134,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "56\n" + ] + } + ], "source": [ - "# Your code here\n" + "set2 = set(sample_list_2)\n", + "print(len(set2))" ] }, { @@ -118,11 +159,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{6, 7, 9, 11, 15, 16, 19, 22, 24, 29, 34, 35, 37, 39, 40, 45, 46, 50, 52, 54, 56, 59, 64, 66, 67, 69, 70, 73, 74, 78, 84, 87, 91, 93, 95, 97, 98}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set3 = set1.difference(set2)\n", + "print(set3)" ] }, { @@ -134,11 +184,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 33, 96, 99, 4, 43, 44, 13, 18, 21, 88, 92, 61}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set4 = set2.difference(set1)\n", + "print(set4)" ] }, { @@ -150,11 +209,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 2, 3, 5, 12, 14, 17, 20, 23, 25, 26, 27, 28, 30, 31, 32, 36, 38, 42, 47, 48, 49, 51, 53, 55, 57, 58, 60, 62, 63, 65, 71, 72, 75, 76, 77, 80, 81, 82, 83, 85, 86, 94}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set5 = set1.intersection(set2)\n", + "print(set5)" ] }, { @@ -186,11 +254,73 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n", + "56\n", + "37\n", + "13\n", + "43\n" + ] + } + ], + "source": [ + "print(len(set1))\n", + "print(len(set2)) \n", + "print(len(set3))\n", + "print(len(set4))\n", + "print(len(set5))" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'len(set1)' is 80\n", + "'len(set2)' is 56\n", + "'len(set3)' is 37\n", + "'len(set4)' is 13\n", + "'len(set5)' is 43\n" + ] + } + ], "source": [ - "# Your code here\n" + "print(f\"'len(set1)' is {len(set3) + len(set5)}\")\n", + "print(f\"'len(set2)' is {len(set4) + len(set5)}\")\n", + "print(f\"'len(set3)' is {len(set1) - len(set5)}\")\n", + "print(f\"'len(set4)' is {len(set2) - len(set5)}\")\n", + "print(f\"'len(set5)' is {len(set1) - len(set3)}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# The math formula that represents the relationship among the values is: set1 = set3 + set4 + (set5 * 2) - set2\n", + "len(set1) == len(set3) + len(set4) + len(set5)*2 - len(set2)" ] }, { @@ -202,11 +332,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# Your code here\n" + "set6 = set()\n", + "print(type(set6))" ] }, { @@ -218,11 +357,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 2, 3, 5, 6, 7, 9, 11, 12, 14, 15, 16, 17, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 42, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 86, 87, 91, 93, 94, 95, 97, 98}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set6.update(set3,set5)\n", + "\n", + "print(set6)" ] }, { @@ -234,11 +383,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set1 == set6" ] }, { @@ -250,11 +410,42 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set2.issubset(set1)" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set3.issubset(set1)" ] }, { @@ -268,11 +459,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set3.union(set4,set5) == set1.union(set2)" ] }, { @@ -284,11 +486,56 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 2, 3, 5, 6, 7, 9, 11, 12, 14, 15, 16, 17, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 42, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 86, 87, 91, 93, 94, 95, 97, 98}\n" + ] + } + ], + "source": [ + "print(set1)" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set1.pop()" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{2, 3, 5, 6, 7, 9, 11, 12, 14, 15, 16, 17, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 42, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 86, 87, 91, 93, 94, 95, 97, 98}\n" + ] + } + ], + "source": [ + "print(set1)" ] }, { @@ -304,11 +551,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{2, 3, 5, 6, 7, 12, 14, 15, 16, 17, 20, 22, 23, 24, 25, 26, 27, 28, 30, 32, 34, 35, 36, 37, 38, 40, 42, 45, 46, 47, 48, 50, 52, 53, 54, 55, 56, 57, 58, 60, 62, 63, 64, 65, 66, 67, 70, 72, 73, 74, 75, 76, 77, 78, 80, 82, 83, 84, 85, 86, 87, 93, 94, 95, 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 item in list_to_remove:\n", + " if item in set1:\n", + " set1.remove(item)\n", + " \n", + "print(set1)" ] } ], @@ -328,7 +589,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..7e6684f 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": 2, "metadata": {}, "outputs": [], "source": [ @@ -49,13 +49,71 @@ "```" ] }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['love', 'conversation', 'every', \"we're\", 'plate', 'sour', 'jukebox', 'now', 'taxi', 'fast', 'bag', 'man', 'push', 'baby', 'going', 'you', \"don't\", 'one', 'mind', 'backseat', 'friends', 'then', 'know', 'take', 'play', 'okay', 'so', 'begin', 'start', 'over', 'body', 'boy', 'just', 'we', 'are', 'girl', 'tell', 'singing', 'drinking', 'put', 'our', 'where', \"i'll\", 'all', \"isn't\", 'make', 'lover', 'get', 'radio', 'give', \"i'm\", 'like', 'can', 'doing', 'with', 'club', 'come', 'it', 'somebody', 'handmade', 'out', 'new', 'room', 'chance', 'follow', 'in', 'may', 'brand', 'that', 'magnet', 'up', 'first', 'and', 'pull', 'of', 'table', 'much', 'last', 'i', 'thrifty', 'grab', 'was', 'driver', 'slow', 'dance', 'the', 'say', 'trust', 'family', 'week', 'date', 'me', 'do', 'waist', 'smell', 'day', 'although', 'your', 'leave', 'want', \"let's\", 'lead', 'at', 'hand', 'how', 'talk', 'not', 'eat', 'falling', 'about', 'story', 'sweet', 'best', 'crazy', 'let', 'too', 'van', 'shots', 'go', 'to', 'a', 'my', 'is', 'place', 'find', 'shape', 'on', 'kiss', 'were', 'night', 'heart', 'for', 'discovering', 'something', 'be', 'bedsheets', 'fill', 'hours', 'stop', 'bar']\n" + ] + } + ], + "source": [ + "keys = list(word_freq.keys())\n", + "print(keys)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['a', 'about', 'all', 'although', 'and', 'are', 'at', 'baby', 'backseat', 'bag', 'bar', 'be', 'bedsheets', 'begin', 'best', 'body', 'boy', 'brand', 'can', 'chance', 'club', 'come', 'conversation', 'crazy', 'dance', 'date', 'day', 'discovering', 'do', 'doing', \"don't\", 'drinking', 'driver', 'eat', 'every', 'falling', 'family', 'fast', 'fill', 'find', 'first', 'follow', 'for', 'friends', 'get', 'girl', 'give', 'go', 'going', 'grab', 'hand', 'handmade', 'heart', 'hours', 'how', 'i', \"i'll\", \"i'm\", 'in', 'is', \"isn't\", 'it', 'jukebox', 'just', 'kiss', 'know', 'last', 'lead', 'leave', 'let', \"let's\", 'like', 'love', 'lover', 'magnet', 'make', 'man', 'may', 'me', 'mind', 'much', 'my', 'new', 'night', 'not', 'now', 'of', 'okay', 'on', 'one', 'our', 'out', 'over', 'place', 'plate', 'play', 'pull', 'push', 'put', 'radio', 'room', 'say', 'shape', 'shots', 'singing', 'slow', 'smell', 'so', 'somebody', 'something', 'sour', 'start', 'stop', 'story', 'sweet', 'table', 'take', 'talk', 'taxi', 'tell', 'that', 'the', 'then', 'thrifty', 'to', 'too', 'trust', 'up', 'van', 'waist', 'want', 'was', 'we', \"we're\", 'week', 'were', 'where', 'with', 'you', 'your']\n" + ] + } + ], + "source": [ + "keys.sort()\n", + "print(keys)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "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": [ + "word_freq2 = {}\n", + "\n", + "for i in keys:\n", + " word_freq2[i] = word_freq[i]\n", + "\n", + "print(word_freq2)" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "\n" ] }, { @@ -92,11 +150,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "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": [ + "import operator\n", + "sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))\n", + "print(sorted_tups)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "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\n" + "word_freq_2 = {}\n", + "\n", + "for i in sorted_tups:\n", + " word_freq_2[i[0]] = word_freq[i[0]]\n", + " \n", + "print(word_freq_2)" ] } ], @@ -116,7 +206,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.11.4" }, "nbTranslate": { "displayLangs": [