diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 48f6b46..113e5c0 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -15,11 +15,11 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup = (\"I\",)" ] }, { @@ -33,11 +33,20 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# Your code here" + "typ = type(tup)\n", + "print(typ)" ] }, { @@ -55,13 +64,36 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "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)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Your code here\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mtup\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"r\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mtup\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"o\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mtup\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"n\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'" + ] + } + ], "source": [ "# Your code here\n", "\n", - "# Your explanation here\n" + "tup.append(\"r\")\n", + "tup.append(\"o\")\n", + "tup.append(\"n\")\n", + "tup.append(\"h\")\n", + "tup.append(\"a\")\n", + "tup.append(\"c\")\n", + "tup.append(\"k\")\n", + "\n", + "\n", + "# Your explanation here\n", + "\n", + "#Tuples are an inmutable kind of object\n" ] }, { @@ -79,13 +111,26 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ "# Your code here\n", "\n", - "# Your explanation here\n" + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "print(tup)\n", + "\n", + "# Your explanation here\n", + "\n", + "#Yes, we're able to change it as long as we are redifining the variable" ] }, { @@ -103,11 +148,25 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "tup1 is: ('I', 'r', 'o', 'n')\n", + "tup2 is: ('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "l=len(tup)\n", + "tup1 = tup[:int(a/2)]\n", + "tup2 = tup[-int(a/2):]\n", + "print(\"tup1 is:\",tup1)\n", + "print(\"tup2 is:\",tup2)\n" ] }, { @@ -121,11 +180,26 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", + "True\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "tup3 = tup1+tup2\n", + "print(tup3)\n", + "\n", + "check = tup3 == tup\n", + "print(check)\n" ] }, { @@ -137,11 +211,27 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 38, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "count1 = len(tup1)\n", + "count2 = len(tup2)\n", + "count12 = count1+count2\n", + "count3 = len(tup3)\n", + "\n", + "check12_3 = count12 == count3\n", + "print(check12_3)\n" ] }, { @@ -153,11 +243,23 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "\n", + "h_ind = tup3.index(\"h\")\n", + "\n", + "print(h_ind)" ] }, { @@ -177,11 +279,32 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a : True\n", + "b : False\n", + "c : True\n", + "d : False\n", + "e : False\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "\n", + "for i in letters:\n", + " if i in tup3:\n", + " print(i,\":\",True)\n", + " else:\n", + " print(i,\":\",False)\n", + "\n" ] }, { @@ -195,11 +318,37 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 59, "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" + "# Your code here\n", + "\n", + "\n", + "dict_1 = {}\n", + "for i in tup3:\n", + " if i in dict_1:\n", + " dict_1[i] += 1\n", + " else:\n", + " dict_1[i] = 1\n", + "\n", + "for j in letters:\n", + " if j in tup3:\n", + " print(j,\":\",dict_1[j])\n", + " else:\n", + " print(j,\":\",0) \n" ] }, { @@ -211,12 +360,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "11\n", + "12\n", + "13\n", + "14\n", + "15\n", + "16\n", + "17\n", + "18\n", + "19\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "tupl = (10,20)\n", + "(min1,max1) = tupl\n", + "\n", + "for i in range(min1,max1+1):\n", + " print(i)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -235,7 +414,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.9.2" } }, "nbformat": 4, diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index ef7bde3..3147337 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": [ @@ -38,11 +38,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[35, 69, 1, 18, 91, 39, 84, 36, 6, 68, 92, 15, 94, 8, 47, 70, 71, 99, 43, 16, 80, 56, 45, 83, 26, 46, 58, 90, 5, 14, 29, 17, 3, 13, 93, 12, 20, 60, 59, 11, 61, 77, 88, 87, 31, 41, 30, 52, 97, 21, 64, 27, 66, 42, 10, 33, 7, 0, 85, 62, 65, 78, 53, 76, 44, 22, 82, 49, 28, 57, 38, 89, 32, 25, 81, 75, 37, 34, 95, 19]\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "sample_list_1 = random.sample(range(100),80)\n", + "print(sample_list_1)" ] }, { @@ -54,11 +65,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n" + ] + } + ], + "source": [ + "# Your code here\n", + "set1 = set(sample_list_1)\n", + "l = len(set1)\n", + "print(l)\n", + "\n", + "#Yes, the length is still 80" ] }, { @@ -77,11 +101,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[73, 86, 2, 10, 0, 9, 6, 20, 87, 5, 39, 74, 63, 78, 92, 97, 20, 50, 56, 14, 3, 45, 70, 17, 15, 33, 95, 26, 0, 77, 62, 32, 65, 43, 88, 13, 77, 24, 12, 8, 9, 23, 76, 90, 11, 18, 89, 25, 20, 24, 28, 6, 65, 17, 31, 37, 51, 80, 77, 20, 37, 65, 84, 83, 65, 71, 73, 42, 95, 2, 2, 55, 92, 99, 67, 29, 10, 79, 58, 26]\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\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 +130,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "59\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set2 = set(sample_list_2)\n", + "l2 = len(set2)\n", + "print(l2)\n", + "\n", + "# No. This time there were repeated numbers and so the repetitions were erased to create the set" ] }, { @@ -109,11 +160,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 7, 16, 19, 21, 22, 27, 30, 34, 35, 36, 38, 41, 44, 46, 47, 49, 52, 53, 57, 59, 60, 61, 64, 66, 68, 69, 75, 81, 82, 85, 91, 93, 94}\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set3 = set1-set2\n", + "print(set3)\n" ] }, { @@ -125,11 +187,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{2, 67, 9, 73, 74, 79, 50, 51, 55, 86, 23, 24, 63}\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set4 = set2-set1\n", + "print(set4)\n" ] }, { @@ -141,11 +214,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 17, 18, 20, 25, 26, 28, 29, 31, 32, 33, 37, 39, 42, 43, 45, 56, 58, 62, 65, 70, 71, 76, 77, 78, 80, 83, 84, 87, 88, 89, 90, 92, 95, 97, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "set5 = set1 - set3 -set4\n", + "print(set5)" ] }, { @@ -165,11 +248,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "True\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "c1 = len(set5)+len(set3) == len(set1)\n", + "c2 = len(set5)+len(set4) == len(set2)\n", + "\n", + "print(c1)\n", + "print(c2)" ] }, { @@ -181,11 +279,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set()\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set6 = set()\n", + "print(set6)" ] }, { @@ -197,11 +306,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 52, 53, 56, 57, 58, 59, 60, 61, 62, 64, 65, 66, 68, 69, 70, 71, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 97, 99}\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set6.update(set3,set5)\n", + "print(set6)" ] }, { @@ -213,11 +333,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "check16 = set1==set6\n", + "print(check16)" ] }, { @@ -229,11 +360,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "ch2in1 = set2.issubset(set1)\n", + "print(ch2in1)\n", + "\n", + "ch3in1 = set3.issubset(set1)\n", + "print(ch3in1)" ] }, { @@ -247,11 +393,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "s345 = set3.union(set4,set5)\n", + "\n", + "s12 = set1.union(set2)\n", + "\n", + "c12345 = s12 == s345\n", + "print(c12345)" ] }, { @@ -263,11 +424,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 52, 53, 56, 57, 58, 59, 60, 61, 62, 64, 65, 66, 68, 69, 70, 71, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 97, 99}\n", + "{1, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 52, 53, 56, 57, 58, 59, 60, 61, 62, 64, 65, 66, 68, 69, 70, 71, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 97, 99}\n" + ] + } + ], + "source": [ + "# Your code here\n", + "print(set1)\n", + "\n", + "set1.pop()\n", + "\n", + "\n", + "print(set1)" ] }, { @@ -283,11 +459,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{3, 5, 6, 7, 8, 10, 12, 13, 14, 15, 16, 17, 18, 20, 22, 25, 26, 27, 28, 30, 32, 33, 34, 35, 36, 37, 38, 42, 43, 44, 45, 46, 47, 52, 53, 56, 57, 58, 60, 62, 64, 65, 66, 68, 70, 75, 76, 77, 78, 80, 82, 83, 84, 85, 87, 88, 90, 92, 93, 94, 95, 97}\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\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", + "set_to_remove = set(list_to_remove)\n", + "\n", + "set1 -= set_to_remove\n", + "\n", + "print(set1)" ] } ], @@ -307,7 +499,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.9.2" } }, "nbformat": 4, diff --git a/your-code/challenge-3.ipynb b/your-code/challenge-3.ipynb index 74d65e0..9128c67 100644 --- a/your-code/challenge-3.ipynb +++ b/your-code/challenge-3.ipynb @@ -21,11 +21,12 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "dict1 = {\"Penelope\":178,\"Arnau\":172,\"Marta\":175}" ] }, { @@ -37,11 +38,28 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "keys: dict_keys(['Penelope', 'Arnau', 'Marta'])\n", + "values: dict_values([178, 172, 175])\n", + "items: dict_items([('Penelope', 178), ('Arnau', 172), ('Marta', 175)])\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "key1 = dict1.keys()\n", + "val1 = dict1.values()\n", + "it1 = dict1.items()\n", + "\n", + "print(\"keys:\",key1)\n", + "print(\"values:\",val1)\n", + "print(\"items:\",it1)" ] }, { @@ -53,11 +71,21 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175, 'Nacho': 187}\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "dict1[\"Nacho\"] = 187\n", + "print(dict1)" ] }, { @@ -69,11 +97,22 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175}\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "del dict1[\"Nacho\"]\n", + "\n", + "print(dict1)" ] }, { @@ -87,7 +126,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -121,11 +160,30 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 22, "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" + "# Your code here\n", + "\n", + "keys = list(word_freq.keys())\n", + "\n", + "keys.sort()\n", + "\n", + "word_freq2 = {}\n", + "\n", + "for i in keys:\n", + " word_freq2[i] = word_freq[i]\n", + "\n", + "print(word_freq2)" ] }, { @@ -162,11 +220,29 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 23, "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" + "# Your code here\n", + "\n", + "import operator\n", + "\n", + "sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))\n", + "word_freq3 = {}\n", + "\n", + "for i in sorted_tups:\n", + " word_freq3[i[0]] = i[1]\n", + " \n", + "print(word_freq3)" ] } ], @@ -186,7 +262,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.9.2" } }, "nbformat": 4,