diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 48f6b46..d78526e 100755 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -15,11 +15,12 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "# Your code here\n", + "tup = (\"I\",)" ] }, { @@ -33,11 +34,20 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "print(type(tup))" ] }, { @@ -55,13 +65,32 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'tuple' object has no attribute 'append'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# Your code here\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mtup\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"r\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"o\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"n\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"h\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"a\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"c\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"k\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'" + ] + } + ], "source": [ "# Your code here\n", - "\n", - "# Your explanation here\n" + "tup.append(\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Your explanation here:\n", + "Tuples are unchangeable, so we cannot add any elements to the tuple." ] }, { @@ -79,13 +108,21 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Your code here\n", - "\n", - "# Your explanation here\n" + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "print(\"Tup is: \", tup)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Your explanation here\n", + "We cannot add any elements to a tuple, but we are able to re-assign the tuples." ] }, { @@ -103,11 +140,15 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "\n", + "tup1 = tup[0:4]\n", + "tup2 = tup[-4:]" ] }, { @@ -121,11 +162,20 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "\n", + "tup3 = tup1 + tup2\n", + "print(tup3)\n", + "\n", + "if tup3 == tup:\n", + " print(\"True. Tup3 equals tup\")\n", + "else:\n", + " print(\"Not the same tup3 than tup\")" ] }, { @@ -137,11 +187,19 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "print(\"Number of elements in tup1 is \", len(set(tup1)))\n", + "print(\"Number of elements in tup2 is \", len(set(tup2)))\n", + "print(\"Number of elements in tup3 is \", len(set(tup3)))\n", + "\n", + "if len(set(tup3)) == sum([len(set(tup1)),len(set(tup2))]):\n", + " print(\"True. Elements in tup1+tup2 equals elements in tup3\")\n", + "else:\n", + " print(\"False\")" ] }, { @@ -153,11 +211,13 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "# Your code here\n", + "print(tup3)\n", + "tup3.index(\"h\")" ] }, { @@ -177,11 +237,19 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "print(letters)\n", + "\n", + "for i in letters:\n", + " if i in tup3:\n", + " print(\"True\")\n", + " else:\n", + " print(\"False\")" ] }, { @@ -195,11 +263,14 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "for i in letters:\n", + " print(tup3.count(i))" ] }, { @@ -215,7 +286,18 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "a, b, c, d, e, f, g, h, i, j = range(10, 20)\n", + "print(a)\n", + "print(b)\n", + "print(c)\n", + "print(d)\n", + "print(e)\n", + "print(f)\n", + "print(g)\n", + "print(h)\n", + "print(i)\n", + "print(j)" ] } ], @@ -235,7 +317,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..7ee067a 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,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[6, 5, 52, 61, 82, 11, 58, 96, 28, 20, 68, 98, 87, 38, 24, 37, 72, 57, 36, 94, 16, 47, 44, 76, 1, 45, 39, 21, 75, 79, 84, 62, 90, 85, 30, 80, 3, 2, 18, 22, 83, 10, 4, 14, 26, 43, 34, 49, 81, 0, 67, 12, 97, 99, 59, 63, 23, 70, 29, 7, 53, 78, 32, 33, 41, 51, 40, 9, 66, 92, 54, 71, 56, 73, 55, 88, 89, 93, 95, 27]\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "sample_list_1 = random.sample(range(100), 80)\n", + "print(sample_list_1)" ] }, { @@ -54,11 +64,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-----------\n", + "80\n", + "True. Its length is still 80\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set1 = set(sample_list_1)\n", + "\n", + "print(\"-----------\")\n", + "\n", + "print(len(set1))\n", + "\n", + "if len(set1) == 80:\n", + " print(\"True. Its length is still 80\")\n" ] }, { @@ -77,11 +106,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[88, 87, 86, 90, 58, 69, 65, 68, 41, 57, 48, 87, 7, 18, 60, 21, 9, 85, 80, 88, 15, 18, 84, 48, 39, 61, 25, 43, 30, 88, 68, 51, 79, 36, 11, 16, 24, 62, 47, 30, 56, 49, 69, 37, 99, 72, 50, 97, 3, 97, 99, 18, 88, 90, 11, 67, 67, 67, 79, 90, 37, 81, 35, 44, 56, 58, 49, 73, 63, 65, 11, 89, 30, 39, 87, 9, 10, 14, 80, 64]\n", + "-----------\n", + "80\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "sample_list_2 = []\n", + "for i in range(80):\n", + " z = random.randrange(0,100)\n", + " sample_list_2.append(z)\n", + "print(sample_list_2)\n", + "\n", + "print(\"-----------\")\n", + "print(len(sample_list_2))" ] }, { @@ -93,11 +141,34 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{3, 7, 9, 10, 11, 14, 15, 16, 18, 21, 24, 25, 30, 35, 36, 37, 39, 41, 43, 44, 47, 48, 49, 50, 51, 56, 57, 58, 60, 61, 62, 63, 64, 65, 67, 68, 69, 72, 73, 79, 80, 81, 84, 85, 86, 87, 88, 89, 90, 97, 99}\n", + "------------\n", + "51\n", + "Negative. Now, its length is: 51\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set2 = set(sample_list_2)\n", + "print(set2)\n", + "\n", + "print(\"------------\")\n", + "\n", + "print(len(set2))\n", + "\n", + "if len(set2) == 80:\n", + " print(\"True. Its length is still 80\")\n", + "else:\n", + " print(\"Negative. Now, its length is: \", len(set2))" ] }, { @@ -109,11 +180,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": [ + "{0, 1, 2, 4, 5, 6, 12, 20, 22, 23, 26, 27, 28, 29, 32, 33, 34, 38, 40, 45, 52, 53, 54, 55, 59, 66, 70, 71, 75, 76, 78, 82, 83, 92, 93, 94, 95, 96, 98}\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set3 = set1 - set2\n", + "print(set3)" ] }, { @@ -125,11 +207,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": [ + "{64, 65, 35, 69, 15, 48, 50, 86, 25, 60}\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set4 = set2 - set1\n", + "print(set4)" ] }, { @@ -141,11 +234,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set5 = {3, 7, 9, 10, 11, 14, 16, 18, 21, 24, 30, 36, 37, 39, 41, 43, 44, 47, 49, 51, 56, 57, 58, 61, 62, 63, 67, 68, 72, 73, 79, 80, 81, 84, 85, 87, 88, 89, 90, 97, 99}\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set5 = set1.intersection(set2)\n", + "\n", + "print('set5 =', set1.intersection(set2))" ] }, { @@ -165,11 +270,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80 because the values are unique numbers\n", + "51 because they were not all unique numbers, then some were repeated\n", + "39 because was set1 - set2 to get only the ones in set1\n", + "10 because was set2 - set1 to get only the ones in set2\n", + "41 because it's the intersection between set1 and set2\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "print(len(set1), \" because the values are unique numbers\")\n", + "print(len(set2), \" because they were not all unique numbers, then some were repeated\")\n", + "print(len(set3), \" because was set1 - set2 to get only the ones in set1\")\n", + "print(len(set4), \" because was set2 - set1 to get only the ones in set2\")\n", + "print(len(set5), \" because it's the intersection between set1 and set2\")" ] }, { @@ -181,11 +304,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "set6 = set()" ] }, { @@ -197,11 +322,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, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 14, 16, 18, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 32, 33, 34, 36, 37, 38, 39, 40, 41, 43, 44, 45, 47, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 66, 67, 68, 70, 71, 72, 73, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 92, 93, 94, 95, 96, 97, 98, 99}\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set6.update(set3,set5)\n", + "print(set6)" ] }, { @@ -213,11 +349,24 @@ }, { "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, they are equal\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "if set1 == set6:\n", + " print(\"True, they are equal\")\n", + "else:\n", + " print(\"Negative, they are not equal\")\n" ] }, { @@ -229,11 +378,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", + "z = set2.issubset(set1)\n", + "print(z)\n", + "\n", + "y = set3.issubset(set1)\n", + "print(y)" ] }, { @@ -247,11 +411,39 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 14, 15, 16, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 97, 98, 99}\n", + "{0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 14, 15, 16, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 97, 98, 99}\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code here\n", + "\n", + "set7 = set3.union(set4,set5)\n", + "\n", + "set8 = set1.union(set2)\n", + "\n", + "print(set7)\n", + "print(set8)\n", + "\n", + "set7 == set8" ] }, { @@ -263,11 +455,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 14, 16, 18, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 32, 33, 34, 36, 37, 38, 39, 40, 41, 43, 44, 45, 47, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 66, 67, 68, 70, 71, 72, 73, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 92, 93, 94, 95, 96, 97, 98, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "set1.pop()\n", + "print(set1)" ] }, { @@ -283,11 +485,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{2, 3, 4, 5, 6, 7, 10, 12, 14, 16, 18, 20, 22, 23, 24, 26, 27, 28, 30, 32, 33, 34, 36, 37, 38, 40, 43, 44, 45, 47, 52, 53, 54, 55, 56, 57, 58, 62, 63, 66, 67, 68, 70, 72, 73, 75, 76, 78, 80, 82, 83, 84, 85, 87, 88, 90, 92, 93, 94, 95, 96, 97, 98}\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", + "set1.difference_update(list_to_remove)\n", + "print(set1)" ] } ], @@ -307,7 +522,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..0d5cc44 100755 --- a/your-code/challenge-3.ipynb +++ b/your-code/challenge-3.ipynb @@ -21,11 +21,13 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "dict1 = {\"Penelope\": 178,\"Arnau\": 172,\"Marta\": 175}" ] }, { @@ -37,11 +39,38 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Penelope\n", + "Arnau\n", + "Marta\n", + "-----------\n", + "178\n", + "172\n", + "175\n", + "-----------\n", + "('Penelope', 178)\n", + "('Arnau', 172)\n", + "('Marta', 175)\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "for i in dict1.keys():\n", + " print(i)\n", + "print(\"-----------\")\n", + "for i in dict1.values():\n", + " print(i)\n", + "print(\"-----------\")\n", + "for i in dict1.items():\n", + " print(i)" ] }, { @@ -52,28 +81,58 @@ ] }, { - "cell_type": "code", - "execution_count": 24, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "# Your code here\n" + "**You can also delete a key from a dictionary using the syntax `del name_of_dict[key_name]`. Try using it to delete the key you just added and then print the dictionary again to see the results.**" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 3, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175, 'Harry': 182}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "**You can also delete a key from a dictionary using the syntax `del name_of_dict[key_name]`. Try using it to delete the key you just added and then print the dictionary again to see the results.**" + "# Your code here\n", + "\n", + "dict1 = {\"Penelope\":178,\n", + " \"Arnau\":172,\n", + " \"Marta\":175}\n", + "\n", + "dict1[\"Harry\"] = 182\n", + "dict1" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175}" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "del dict1[\"Harry\"]\n", + "dict1" ] }, { @@ -85,15 +144,6 @@ "The dictionary below is a summary of the word frequency of Ed Sheeran's song *Shape of You*. Each key is a word in the lyrics and the value is the number of times that word appears in the lyrics." ] }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "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}" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -121,11 +171,52 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 31, "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", + "[8, 1, 1, 3, 23, 1, 1, 14, 1, 1, 1, 16, 3, 1, 1, 17, 2, 6, 1, 1, 1, 37, 1, 2, 1, 1, 6, 6, 3, 2, 2, 1, 1, 1, 6, 3, 1, 1, 2, 1, 1, 6, 3, 1, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 1, 6, 1, 23, 27, 5, 1, 1, 1, 1, 1, 2, 3, 6, 1, 1, 2, 10, 25, 1, 3, 1, 1, 2, 10, 2, 2, 33, 6, 3, 2, 11, 6, 1, 40, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 3, 2, 6, 1, 2, 1, 3, 2, 2, 6, 1, 2, 1, 1, 1, 1, 1, 4, 1, 1, 2, 18, 3, 1, 2, 5, 1, 3, 1, 2, 2, 2, 7, 1, 1, 3, 1, 22, 16, 21]\n" + ] + } + ], + "source": [ + "# Your code here\n", + "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", + "word_freq2 = {}\n", + "\n", + "dictionary_items = word_freq.items()\n", + "keys = sorted(word_freq)\n", + "print(keys)\n", + "\n", + "#Hasta aquí todo genial. Falta añadir el for loop.\n", + "\n", + "values = []\n", + "for value in keys:\n", + " values.append(word_freq[value])\n", + "print(values)\n", + "\n", + "word_freq2 = dict(zip(keys, values))" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "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": [ - "# Your code here\n" + "print(word_freq2)" ] }, { @@ -162,11 +253,27 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 43, "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", + "sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))\n", + "\n", + "word_freq2 = {}\n", + "\n", + "word_freq2 = dict(sorted_tups)\n", + "print(word_freq2)" ] } ], @@ -186,7 +293,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.3" } }, "nbformat": 4,