diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 48f6b46..e9bb172 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": 3, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup = (\"I\",)" ] }, { @@ -33,11 +33,22 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "tuple" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "type(tup)" ] }, { @@ -55,13 +66,11 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n", - "\n", - "# Your explanation here\n" + "list_1 = list(tup)" ] }, { @@ -79,13 +88,29 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 13, + "metadata": { + "scrolled": true + }, + "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)" + ] + }, + { + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "# Your code here\n", - "\n", - "# Your explanation here\n" + "Yes, you can reassign the new elements to the tuple. You change the information on the placeholder tup." ] }, { @@ -103,11 +128,49 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n')\n", + "('h', 'a', 'c', 'k')\n" + ] + } + ], + "source": [ + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "\n", + "tup1 = (tup[:4])\n", + "tup2 = (tup[-4:])\n", + "\n", + "print(tup1)\n", + "print(tup2)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "#list_2 = list(tup)\n", + "\n", + "#tup1 = []\n", + "#tup2 = []\n", + "\n", + "#for i in list_2[:4]:\n", + "# tup1.append(i)\n", + "#for i in list_2[-4:]:\n", + "# tup2.append(i)\n", + "\n", + "#tup1 = tuple(tup1)\n", + "#tup2 = tuple(tup2)\n", + "\n", + "#print(tup1)\n", + "#print(tup2)" ] }, { @@ -121,11 +184,20 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 39, "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 +209,22 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "len(tup1) + len(tup2) == len(tup3)" ] }, { @@ -153,11 +236,22 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 45, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "tup3.index(\"h\")" ] }, { @@ -177,11 +271,31 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 47, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True a is in the tuple.\n", + "False b is not in the tuple.\n", + "True c is in the tuple.\n", + "False d is not in the tuple.\n", + "False e is not in the tuple.\n" + ] + } + ], "source": [ - "# Your code here\n" + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "\n", + "for i in letters:\n", + " if i in tup3:\n", + " print(\"True \", i, \" is in the tuple.\")\n", + " else:\n", + " print(\"False\", i, \" is not in the tuple.\")\n", + " \n", + " \n" ] }, { @@ -195,11 +309,25 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 50, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a 1\n", + "b 1\n", + "c 1\n", + "d 1\n", + "e 1\n" + ] + } + ], "source": [ - "# Your code here\n" + "for i in letters:\n", + " if i in letters:\n", + " print(i, letters.count(i))" ] }, { @@ -211,12 +339,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)\n" + ] + } + ], "source": [ - "# Your code here\n" + "print(tuple(range(10,21)))" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -235,7 +378,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index ef7bde3..23217ff 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": [], + "execution_count": 2, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[77, 25, 51, 74, 40, 91, 56, 43, 79, 84, 17, 48, 23, 45, 73, 54, 20, 68, 58, 24, 35, 33, 46, 75, 31, 27, 72, 8, 59, 3, 6, 97, 12, 92, 28, 98, 34, 37, 87, 49, 50, 93, 90, 88, 4, 26, 47, 94, 65, 57, 11, 29, 30, 82, 80, 13, 55, 83, 38, 76, 66, 39, 16, 69, 1, 70, 62, 2, 71, 32, 14, 42, 0, 52, 22, 21, 81, 5, 18, 15]\n" + ] + } + ], "source": [ - "# Your code here\n" + "sample_list_1 = random.sample(range(0, 100), 80)\n", + "print(sample_list_1)" ] }, { @@ -54,11 +65,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 6, 8, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 62, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 87, 88, 90, 91, 92, 93, 94, 97, 98}\n" + ] + }, + { + "data": { + "text/plain": [ + "80" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set1 = set(sample_list_1)\n", + "print(set1)\n", + "len(set1)\n" ] }, { @@ -77,11 +108,35 @@ }, { "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, 34, 12, 48, 65, 71, 3, 57, 94, 23, 32, 17, 94, 48, 37, 24, 29, 39, 50, 76, 37, 42, 61, 41, 48, 20, 2, 0, 80, 34, 88, 100, 47, 52, 71, 61, 79, 63, 81, 55, 77, 2, 85, 68, 85, 46, 44, 80, 72, 21, 98, 36, 10, 27, 17, 68, 12, 49, 82, 98, 33, 61, 27, 98, 88, 65, 71, 43, 46, 27, 49, 99, 13, 37, 47, 33, 98, 0, 15, 31]\n" + ] + }, + { + "data": { + "text/plain": [ + "80" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sample_list_2 = []\n", + "\n", + "for i in range(0, 80):\n", + " sample_list_2.append(random.randrange(0, 101))\n", + " \n", + "print(sample_list_2)\n", + "len(sample_list_2)" ] }, { @@ -93,11 +148,33 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 2, 3, 10, 12, 13, 15, 17, 20, 21, 23, 24, 27, 29, 31, 32, 33, 34, 36, 37, 39, 41, 42, 43, 44, 46, 47, 48, 49, 50, 52, 55, 57, 61, 63, 65, 68, 71, 72, 76, 77, 79, 80, 81, 82, 85, 88, 94, 98, 99, 100}\n" + ] + }, + { + "data": { + "text/plain": [ + "51" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set2 = set(sample_list_2)\n", + "print(set2)\n", + "len(set2)\n", + "\n", + "#The length changes because list 2 includes same numbers sevral times, however sets only have unique numbers." ] }, { @@ -109,11 +186,25 @@ }, { "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, 4, 5, 6, 8, 11, 14, 16, 18, 22, 25, 26, 28, 30, 35, 38, 40, 45, 51, 54, 56, 58, 59, 62, 66, 69, 70, 73, 74, 75, 83, 84, 87, 90, 91, 92, 93, 97}\n" + ] + } + ], + "source": [ + "set3 = []\n", + "\n", + "for i in set1:\n", + " if i not in set2:\n", + " set3.append(i)\n", + "set3 = set(set3) \n", + "print(set3)\n" ] }, { @@ -125,11 +216,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{99, 36, 100, 41, 10, 44, 85, 61, 63}\n" + ] + } + ], + "source": [ + "set4 = []\n", + "\n", + "for nr in set2:\n", + " if nr not in set1:\n", + " set4.append(nr)\n", + "set4 = set(set4) \n", + "print(set(set4))\n" ] }, { @@ -141,11 +246,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 2, 3, 12, 13, 15, 17, 20, 21, 23, 24, 27, 29, 31, 32, 33, 34, 37, 39, 42, 43, 46, 47, 48, 49, 50, 52, 55, 57, 65, 68, 71, 72, 76, 77, 79, 80, 81, 82, 88, 94, 98}\n" + ] + } + ], + "source": [ + "set5 = []\n", + "\n", + "for nbr in set1:\n", + " if nbr in set2:\n", + " set5.append(nbr)\n", + "set5 = set(set5) \n", + "print(set(set5))" ] }, { @@ -165,11 +284,35 @@ }, { "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\n", + "51\n", + "38\n", + "9\n", + "42\n" + ] + } + ], + "source": [ + "a = len(set1)\n", + "b = len(set2)\n", + "c = len(set3)\n", + "d = len(set4)\n", + "e = len(set5)\n", + "\n", + "print(a)\n", + "print(b)\n", + "print(c)\n", + "print(d)\n", + "print(e)\n", + "\n", + "#There is not a certain relation between those numbers." ] }, { @@ -181,11 +324,13 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 10, + "metadata": { + "scrolled": false + }, "outputs": [], "source": [ - "# Your code here\n" + "set6 = set()\n" ] }, { @@ -197,11 +342,69 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 6, 8, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 62, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 87, 88, 90, 91, 92, 93, 94, 97, 98}\n", + "{0, 2, 3, 10, 12, 13, 15, 17, 20, 21, 23, 24, 27, 29, 31, 32, 33, 34, 36, 37, 39, 41, 42, 43, 44, 46, 47, 48, 49, 50, 52, 55, 57, 61, 63, 65, 68, 71, 72, 76, 77, 79, 80, 81, 82, 85, 88, 94, 98, 99, 100}\n", + "{1, 4, 5, 6, 8, 11, 14, 16, 18, 22, 25, 26, 28, 30, 35, 38, 40, 45, 51, 54, 56, 58, 59, 62, 66, 69, 70, 73, 74, 75, 83, 84, 87, 90, 91, 92, 93, 97}\n", + "{99, 36, 100, 41, 10, 44, 85, 61, 63}\n", + "{0, 2, 3, 12, 13, 15, 17, 20, 21, 23, 24, 27, 29, 31, 32, 33, 34, 37, 39, 42, 43, 46, 47, 48, 49, 50, 52, 55, 57, 65, 68, 71, 72, 76, 77, 79, 80, 81, 82, 88, 94, 98}\n", + "set()\n" + ] + } + ], + "source": [ + "print(set1)\n", + "print(set2)\n", + "print(set3)\n", + "print(set4)\n", + "print(set5)\n", + "print(set6)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 6, 8, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 62, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 87, 88, 90, 91, 92, 93, 94, 97, 98}\n" + ] + } + ], + "source": [ + "set6.update(set5, set3)\n", + "print(set6)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 6, 8, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 62, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 87, 88, 90, 91, 92, 93, 94, 97, 98}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set6.update(set3)\n", + "print(set6)" ] }, { @@ -213,11 +416,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set1 == set6" ] }, { @@ -229,11 +443,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], + "source": [ + "y = set2.issubset(set1)\n", + "print(y)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ - "# Your code here\n" + "x = set3.issubset(set1)\n", + "print(x)" ] }, { @@ -247,11 +488,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 17, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 61, 62, 63, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 85, 87, 88, 90, 91, 92, 93, 94, 97, 98, 99, 100}\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "z = set3.union(set4, set5)\n", + "print(z)\n", + "\n", + "y = set1.union(set2)\n", + "\n", + "y == z\n" ] }, { @@ -263,11 +529,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 6, 8, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 62, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 87, 88, 90, 91, 92, 93, 94, 97, 98}\n", + "{1, 2, 3, 4, 5, 6, 8, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 62, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 87, 88, 90, 91, 92, 93, 94, 97, 98}\n" + ] + } + ], + "source": [ + "print(set1)\n", + "\n", + "set1 = list(set1)\n", + "\n", + "set1.pop(0)\n", + "\n", + "print(set(set1))" ] }, { @@ -283,11 +564,28 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{2, 3, 4, 5, 6, 8, 12, 13, 14, 15, 16, 17, 18, 20, 22, 23, 24, 25, 26, 27, 28, 30, 32, 33, 34, 35, 37, 38, 40, 42, 43, 45, 46, 47, 48, 50, 52, 54, 55, 56, 57, 58, 62, 65, 66, 68, 70, 72, 73, 74, 75, 76, 77, 80, 82, 83, 84, 87, 88, 90, 92, 93, 94, 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", + "set1 = list(set1)\n", + "\n", + "for i in list_to_remove:\n", + " if i in set1:\n", + " set1.remove(i)\n", + " \n", + "set1 = set(set1)\n", + "\n", + "print(set1)\n" ] } ], @@ -307,7 +605,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/your-code/challenge-3.ipynb b/your-code/challenge-3.ipynb index 74d65e0..7cc5701 100644 --- a/your-code/challenge-3.ipynb +++ b/your-code/challenge-3.ipynb @@ -21,11 +21,11 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "dict1 = {\"Penelope\" : 178, \"Arnau\" : 172, \"Marta\" : 175}\n" ] }, { @@ -37,11 +37,62 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['Penelope', 'Marta', 'Jonathan'])" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "dict1.keys()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_values([178, 172, 175])" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dict1.values()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_items([('Penelope', 178), ('Arnau', 172), ('Marta', 175)])" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dict1.items()" ] }, { @@ -53,11 +104,20 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175, 'Jonathan': 180}\n" + ] + } + ], "source": [ - "# Your code here\n" + "dict1[\"Jonathan\"] = 180\n", + "print(dict1)\n" ] }, { @@ -69,11 +129,21 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Penelope': 178, 'Marta': 175, 'Jonathan': 180}\n" + ] + } + ], "source": [ - "# Your code here\n" + "del dict1[\"Arnau\"]\n", + "\n", + "print(dict1)\n" ] }, { @@ -87,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -121,11 +191,30 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 19, "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" + "word_freq2 = {}\n", + "\n", + "keys = list(word_freq.keys())\n", + "\n", + "keys.sort()\n", + "\n", + "#name_of_dict[key_name] = value\n", + "\n", + "for i in keys:\n", + " word_freq2[i] = word_freq[i]\n", + " \n", + "print(word_freq2)\n" ] }, { @@ -162,12 +251,53 @@ }, { "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": [ + "word_freq2 = {}\n", + "\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", + "\n", + "import operator\n", + "sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))\n", + "print(sorted_tups)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "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_freq2.update(sorted_tups)\n", + "\n", + "print(word_freq2)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -186,7 +316,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.8" } }, "nbformat": 4,