From 584714d27c2c49b309c20fd929232c486ff7b3db Mon Sep 17 00:00:00 2001 From: Dirk Gruhne Date: Wed, 21 Oct 2020 00:48:56 +0200 Subject: [PATCH] My todays work Lab Data types --- your-code/challenge-1.ipynb | 293 ++++++++++++++++++++++++++++++++---- your-code/challenge-2.ipynb | 252 +++++++++++++++++++++++++------ your-code/challenge-3.ipynb | 131 ++++++++++++++-- 3 files changed, 578 insertions(+), 98 deletions(-) diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 48f6b46..50213ba 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": 2, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup = (\"I\",)" ] }, { @@ -33,11 +33,22 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "tuple" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "type(tup)" ] }, { @@ -55,13 +66,24 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (, line 3)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m Imposible, tuples are not mutable# Your code here\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + ] + } + ], "source": [ - "# Your code here\n", + "tup.append(tup)\n", "\n", - "# Your explanation here\n" + "Imposible, tuples are not mutable\n", + "\n", + "\n" ] }, { @@ -79,13 +101,24 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n", - "\n", - "# Your explanation here\n" + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "tup\n", + "# No, but converting it into a list it should work\n" ] }, { @@ -103,11 +136,24 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n')\n", + "('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "\n", + "tup1 = tup[:4]\n", + "tup2 = tup[-4:]\n", + "print(tup1)\n", + "print(tup2)\n" ] }, { @@ -121,11 +167,20 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 38, "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)" ] }, { @@ -137,11 +192,28 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "4\n", + "8\n" + ] + } + ], "source": [ - "# Your code here\n" + "number_elements_tup1 = len(tup1)\n", + "number_elements_tup2 = len(tup2)\n", + "number_elements_tup2_3 = len(tup1) + len(tup2)\n", + "print(len(tup1))\n", + "print(len(tup2))\n", + "print(number_elements_tup2_3)\n", + "\n", + "\n" ] }, { @@ -153,11 +225,20 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h\n" + ] + } + ], "source": [ - "# Your code here" + "index_h_tup3 = tup[4]\n", + "print(index_h_tup3)" ] }, { @@ -177,11 +258,136 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 51, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "True\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "True\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "True\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "True\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "True\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "True\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "False\n", + "True\n" + ] + } + ], "source": [ - "# Your code here\n" + "#for i in letters:\n", + "for i in tup3:\n", + " if i == \"I\":\n", + " print(\"True\")\n", + " else:\n", + " print(\"False\")\n", + "\n", + "\n", + "for i in tup3:\n", + " if i == \"r\":\n", + " print(\"True\")\n", + " else:\n", + " print(\"False\")\n", + "\n", + "\n", + "for i in tup3:\n", + " if i == \"o\":\n", + " print(\"True\")\n", + " else:\n", + " print(\"False\")\n", + "\n", + " \n", + "for i in tup3:\n", + " if i == \"n\":\n", + " print(\"True\")\n", + " else:\n", + " print(\"False\")\n", + "\n", + "\n", + "for i in tup3:\n", + " if i == \"h\":\n", + " print(\"True\")\n", + " else:\n", + " print(\"False\")\n", + "\n", + "\n", + "for i in tup3:\n", + " if i == \"a\":\n", + " print(\"True\")\n", + " else:\n", + " print(\"False\")\n", + "\n", + "\n", + "for i in tup3:\n", + " if i == \"c\":\n", + " print(\"True\")\n", + " else:\n", + " print(\"False\")\n", + "\n", + " \n", + "for i in tup3:\n", + " if i == \"k\":\n", + " print(\"True\")\n", + " else:\n", + " print(\"False\")" ] }, { @@ -195,11 +401,32 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 55, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The letter l occurs: 0 times\n", + "The letter e occurs: 0 times\n", + "The letter t occurs: 0 times\n", + "The letter r occurs: 1 times\n", + "The letter s occurs: 0 times\n" + ] + } + ], "source": [ - "# Your code here\n" + "count_l = tup.count('l')\n", + "print(\"The letter l occurs: \" + str(count_l) + \" times\")\n", + "count_l = tup.count('e')\n", + "print(\"The letter e occurs: \" + str(count_l) + \" times\")\n", + "count_l = tup.count('t')\n", + "print(\"The letter t occurs: \" + str(count_l) + \" times\")\n", + "count_l = tup.count('r')\n", + "print(\"The letter r occurs: \" + str(count_l) + \" times\")\n", + "count_l = tup.count('s')\n", + "print(\"The letter s occurs: \" + str(count_l) + \" times\")" ] }, { @@ -235,7 +462,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..d7e9fbe 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,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[90, 77, 67, 76, 34, 0, 21, 60, 31, 10, 40, 87, 59, 92, 79, 39, 53, 71, 15, 65, 51, 63, 42, 49, 26, 5, 6, 80, 13, 75, 54, 46, 33, 17, 27, 35, 83, 88, 19, 32, 58, 82, 70, 73, 57, 69, 91, 11, 62, 55, 9, 16, 74, 85, 81, 68, 1, 72, 18, 78, 4, 3, 61, 38, 97, 12, 14, 66, 45, 50, 24, 52, 7, 47, 84, 41, 20, 22, 37, 99]\n" + ] + } + ], + "source": [ + "import random\n", + "\n", + "sample_list_1 = random.sample(range(100),80)\n", + "\n", + "print(sample_list_1)\n", + "\n" ] }, { @@ -54,10 +67,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 27, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 87, 88, 90, 91, 92, 97, 99}\n", + "80\n" + ] + } + ], + "source": [ + "set1 = set(sample_list_1)\n", + "print(set1)\n", + "print(len(set1))\n", "# Your code here\n" ] }, @@ -77,11 +102,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[20, 50, 30, 33, 20, 39, 26, 18, 57, 66, 36, 35, 12, 24, 4, 30, 54, 46, 4, 61, 18, 32, 1, 2, 24, 30, 71, 32, 52, 36, 65, 30, 46, 43, 44, 33, 8, 45, 62, 70, 76, 68, 50, 40, 41, 72, 46, 26, 58, 28, 68, 30, 50, 39, 78, 13, 18, 16, 9, 78, 16, 59, 39, 40, 29, 18, 34, 17, 54, 62, 10, 8, 65, 2, 22, 13, 79, 37, 37, 67]\n" + ] + } + ], + "source": [ + "import random\n", + "sample_list_2 = []\n", + "\n", + "for i in range(80):\n", + " a = random.randrange(1,80)\n", + " sample_list_2.append(a)\n", + "\n", + "print(sample_list_2)\n", + "\n" ] }, { @@ -93,11 +134,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 2, 4, 8, 9, 10, 12, 13, 16, 17, 18, 20, 22, 24, 26, 28, 29, 30, 32, 33, 34, 35, 36, 37, 39, 40, 41, 43, 44, 45, 46, 50, 52, 54, 57, 58, 59, 61, 62, 65, 66, 67, 68, 70, 71, 72, 76, 78, 79}\n", + "49\n" + ] + } + ], "source": [ - "# Your code here\n" + "set2 = set(sample_list_2)\n", + "print(set2)\n", + "print(len(set2))\n" ] }, { @@ -109,11 +161,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set()\n" + ] + } + ], "source": [ - "# Your code here\n" + "set3 = set1 - set2\n", + "print(set3)" ] }, { @@ -125,11 +186,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{2, 36, 8, 43, 44, 28, 29, 30}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set4 = set2 - set1\n", + "print(set4)" ] }, { @@ -141,11 +211,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 4, 9, 10, 12, 13, 16, 17, 18, 20, 22, 24, 26, 32, 33, 34, 35, 37, 39, 40, 41, 45, 46, 50, 52, 54, 57, 58, 59, 61, 62, 65, 66, 67, 68, 70, 71, 72, 76, 78, 79}\n" + ] + } + ], + "source": [ + "x = set1\n", + "y = set2\n", + "\n", + "set5 = x.intersection(y)\n", + "\n", + "print(set5)\n" ] }, { @@ -169,7 +252,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "len(set1) len(set2) len(set3) len(set4) len(set5) \n" ] }, { @@ -181,11 +264,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "set6 = set()\n" ] }, { @@ -197,11 +280,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 4, 9, 10, 12, 13, 16, 17, 18, 20, 22, 24, 26, 32, 33, 34, 35, 37, 39, 40, 41, 45, 46, 50, 52, 54, 57, 58, 59, 61, 62, 65, 66, 67, 68, 70, 71, 72, 76, 78, 79}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set6.update(set3)\n", + "set6.update(set5)\n", + "print(set6)\n", + "\n" ] }, { @@ -213,11 +307,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Yes\n" + ] + } + ], "source": [ - "# Your code here\n" + "if set1 == set6:\n", + " print(\"Yes\")\n", + "else:\n", + " print(\"No\")\n" ] }, { @@ -229,11 +334,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], "source": [ - "# Your code here\n" + "check1_in2 = set1.issubset(set2)\n", + "check2_in1 = set2.issubset(set1)\n", + "print(check1_in2)\n", + "print(check2_in1)" ] }, { @@ -251,7 +368,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "\n" ] }, { @@ -263,11 +380,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{4, 9, 10, 12, 13, 16, 17, 18, 20, 22, 24, 26, 32, 33, 34, 35, 37, 39, 40, 41, 45, 46, 50, 52, 54, 57, 58, 59, 61, 62, 65, 66, 67, 68, 70, 71, 72, 76, 78, 79}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set1.pop()\n", + "print(set1)\n" ] }, { @@ -281,14 +407,42 @@ "```" ] }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[9, 39, 41, 59, 61, 71, 79]\n", + "{4, 10, 12, 13, 16, 17, 18, 20, 22, 24, 26, 32, 33, 34, 35, 37, 40, 45, 46, 50, 52, 54, 57, 58, 62, 65, 66, 67, 68, 70, 72, 76, 78}\n" + ] + } + ], + "source": [ + "list_to_remove = [1, 9, 11, 19, 21, 29, 31, 39, 41, 49, 51, 59, 61, 69, 71, 79, 81, 89, 91, 99]\n", + "duplicates = []\n", + "for i in set1:\n", + " for j in list_to_remove:\n", + " if i == j:\n", + " duplicates.append(j)\n", + "print(duplicates)\n", + "\n", + "for x in duplicates:\n", + " set1.remove(x)\n", + " \n", + "print(set1)\n", + " " + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "# Your code here\n" - ] + "source": [] } ], "metadata": { @@ -307,7 +461,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..14ec799 100755 --- a/your-code/challenge-3.ipynb +++ b/your-code/challenge-3.ipynb @@ -21,10 +21,23 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175}\n" + ] + } + ], "source": [ + "dict1 = {\"Penelope\": 178,\n", + " \"Arnau\": 172,\n", + " \"Marta\": 175\n", + " }\n", + "print(dict1)\n", "# Your code here\n" ] }, @@ -37,10 +50,25 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 5, "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": [ + "print(dict1.keys())\n", + "print(dict1.values())\n", + "print(dict1.items())\n", + "\n", + "\n", "# Your code here\n" ] }, @@ -53,10 +81,32 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 45, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175, 'Alejo': 172}\n" + ] + }, + { + "data": { + "text/plain": [ + "172" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "dict1[\"Alejo\"] = 172\n", + "print(dict1)\n", + "dict1[\"Alejo\"]\n", + "\n", "# Your code here\n" ] }, @@ -69,11 +119,20 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175}\n" + ] + } + ], "source": [ - "# Your code here\n" + "del dict1[\"Alejo\"]\n", + "print(dict1)\n" ] }, { @@ -87,11 +146,20 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'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" + ] + } + ], "source": [ - "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}" + "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", + "print(word_freq)" ] }, { @@ -121,13 +189,44 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 47, "metadata": {}, - "outputs": [], + "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", + "{'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", + "print(keys)\n", + "\n", + "word_freq2 = {}\n", + "\n", + "# word_freq2[\"your\"] = word_freq[\"your\"]\n", + "# word_freq2[\"you\"] = word_freq[\"you\"]\n", + "# word_freq2[\"with\"] = word_freq[\"with\"]\n", + "#...\n", + "# word_freq2[\"any value\"] = word_freq[\"any value\"]\n", + "\n", + "\n", + "for i in keys:\n", + " word_freq2[i] = word_freq[i]\n", + "print(word_freq2)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -186,7 +285,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.3" } }, "nbformat": 4,