diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 48f6b46..e70ef8e 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": 20, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup = (\"I\",)" ] }, { @@ -33,11 +33,22 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "tuple" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "type(tup)" ] }, { @@ -55,13 +66,26 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 23, "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[1;32m----> 1\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;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mtup\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"o\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;31m#This is not possible because tuples cannot be modified#\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'" + ] + } + ], "source": [ - "# Your code here\n", + "tup.append(\"r\")\n", + "tup.append(\"o\")\n", "\n", - "# Your explanation here\n" + "#This is not possible because tuples cannot be modified#\n" ] }, { @@ -79,13 +103,25 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')" + ] + }, + "execution_count": 29, + "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", + "# Yes because you are re-assigning the tuple\n", + "\n" ] }, { @@ -103,11 +139,24 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n')\n", + "('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "tup1 = tup[0:4]\n", + "tup2 = tup[-4:]\n", + "\n", + "print(tup1)\n", + "print(tup2)\n" ] }, { @@ -121,11 +170,31 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "tup3 = tup1 + tup2\n", + "print(tup3)\n", + "tup3 == tup" ] }, { @@ -137,11 +206,31 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "number_of_elements = len(tup1) + len(tup2)\n", + "print(number_of_elements)\n", + "number_of_elements == len(tup3)" ] }, { @@ -153,11 +242,31 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + }, + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "\n", + "print(tup3)\n", + "tup3.index(\"h\")" ] }, { @@ -177,11 +286,31 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 51, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "False\n", + "False\n" + ] + } + ], "source": [ - "# Your code here\n" + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "ocurrences = []\n", + "for letter in letters :\n", + " if letter in tup3:\n", + " print(True)\n", + " ocurrences.append(True)\n", + " else:\n", + " print(False)\n", + " \n" ] }, { @@ -195,11 +324,22 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 61, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "len(ocurrences)\n" ] }, { @@ -235,7 +375,49 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.3" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false } }, "nbformat": 4, diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index ef7bde3..b9c4120 100755 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -13,11 +13,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "import random" + "import random as rd" ] }, { @@ -38,11 +38,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 127, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[58, 4, 5, 84, 9, 60, 32, 100, 21, 97, 94, 81, 22, 37, 67, 95, 0, 80, 34, 85, 69, 76, 31, 29, 89, 77, 33, 8, 61, 18, 50, 36, 3, 48, 45, 55, 43, 93, 99, 57, 70, 51, 39, 30, 54, 2, 83, 90, 14, 66, 65, 40, 79, 56, 1, 75, 41, 72, 53, 19, 27, 86, 11, 17, 78, 16, 98, 25, 68, 64, 96, 91, 62, 24, 44, 12, 20, 7, 42, 35]\n" + ] + } + ], "source": [ - "# Your code here\n" + "sample_list_1 = rd.sample(range(0,101), 80)\n", + "print(sample_list_1)" ] }, { @@ -54,18 +65,42 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 128, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 7, 8, 9, 11, 12, 14, 16, 17, 18, 19, 20, 21, 22, 24, 25, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 40, 41, 42, 43, 44, 45, 48, 50, 51, 53, 54, 55, 56, 57, 58, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 72, 75, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 89, 90, 91, 93, 94, 95, 96, 97, 98, 99, 100}\n" + ] + }, + { + "data": { + "text/plain": [ + "80" + ] + }, + "execution_count": 128, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set1 = set(sample_list_1)\n", + "print(set1)\n", + "len(set1)\n", + "\n", + "#Yes , it is still 80" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "#### Create another list named `sample_list_2` with 80 random values.\n", + "Create another list named `sample_list_2` with 80 random values.\n", "\n", "Requirements:\n", "\n", @@ -77,11 +112,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 129, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[13, 77, 32, 36, 64, 72, 92, 39, 91, 43, 39, 58, 98, 12, 55, 81, 43, 73, 24, 80, 12, 30, 80, 45, 53, 45, 98, 71, 69, 69, 44, 53, 59, 77, 8, 51, 44, 22, 9, 35, 30, 3, 79, 72, 12, 67, 12, 76, 79, 23, 99, 97, 51, 97, 19, 62, 0, 44, 59, 12, 15, 64, 51, 90, 65, 37, 43, 35, 22, 15, 89, 79, 67, 100, 53, 70, 30, 86, 8, 16]\n" + ] + }, + { + "data": { + "text/plain": [ + "80" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sample_list_2 = []\n", + "for i in range(0, 80):\n", + " i = rd.randrange(0, 101)\n", + " sample_list_2.append(i)\n", + "\n", + "print(sample_list_2)\n", + "len(sample_list_2)\n", + "\n" ] }, { @@ -93,11 +153,35 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 130, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 3, 8, 9, 12, 13, 15, 16, 19, 22, 23, 24, 30, 32, 35, 36, 37, 39, 43, 44, 45, 51, 53, 55, 58, 59, 62, 64, 65, 67, 69, 70, 71, 72, 73, 76, 77, 79, 80, 81, 86, 89, 90, 91, 92, 97, 98, 99, 100}\n" + ] + }, + { + "data": { + "text/plain": [ + "49" + ] + }, + "execution_count": 130, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set2 =set(sample_list_2)\n", + "print(set2)\n", + "len(set2)\n", + "\n", + "#NO, the lenght of the set is 56" ] }, { @@ -109,11 +193,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 131, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 2, 4, 5, 7, 11, 14, 17, 18, 20, 21, 25, 27, 29, 31, 33, 34, 40, 41, 42, 48, 50, 54, 56, 57, 60, 61, 66, 68, 75, 78, 83, 84, 85, 93, 94, 95, 96}\n" + ] + } + ], "source": [ - "# Your code here\n" + "s = []\n", + "for i in set1:\n", + " if i not in set2:\n", + " s.append(i)\n", + " \n", + "set3 = set(s)\n", + "print(set3)" ] }, { @@ -125,11 +223,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 132, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{71, 73, 13, 15, 23, 59, 92}\n" + ] + } + ], + "source": [ + "s4 = []\n", + "for i in set2:\n", + " if i not in set1:\n", + " s4.append(i)\n", + "\n", + "set4 = set(s4)\n", + "print(set4)" ] }, { @@ -141,11 +255,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 133, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 3, 8, 9, 12, 16, 19, 22, 24, 30, 32, 35, 36, 37, 39, 43, 44, 45, 51, 53, 55, 58, 62, 64, 65, 67, 69, 70, 72, 76, 77, 79, 80, 81, 86, 89, 90, 91, 97, 98, 99, 100}\n" + ] + } + ], "source": [ - "# Your code here\n" + "s5 = []\n", + "for i in set1:\n", + " if i in set2:\n", + " s5.append(i)\n", + " \n", + "set5 = set(s5)\n", + "print(set5)\n" ] }, { @@ -165,11 +293,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 135, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 135, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "len(set1) + len(set2) - len(set5) == len(set3) + len(set4) + len(set5)" ] }, { @@ -181,11 +320,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 82, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "s6 = []\n", + "set6 = set(s6)" ] }, { @@ -197,11 +337,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 87, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 3, 4, 5, 7, 8, 11, 13, 14, 15, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 38, 40, 41, 43, 44, 45, 46, 47, 48, 50, 51, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 64, 65, 67, 68, 69, 70, 72, 73, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 86, 89, 90, 92, 93, 94, 95, 96, 97, 98, 99, 100}\n" + ] + } + ], + "source": [ + "set6.update(set3)\n", + "set6.update(set5)\n", + "\n", + "print(set6)" ] }, { @@ -213,11 +364,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set1 == set6\n" ] }, { @@ -229,11 +391,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 92, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set1.issubset(set2)" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set1.issubset(set3)" ] }, { @@ -247,11 +440,246 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{0,\n", + " 1,\n", + " 2,\n", + " 3,\n", + " 4,\n", + " 5,\n", + " 6,\n", + " 7,\n", + " 8,\n", + " 10,\n", + " 11,\n", + " 12,\n", + " 13,\n", + " 14,\n", + " 15,\n", + " 18,\n", + " 19,\n", + " 20,\n", + " 21,\n", + " 22,\n", + " 23,\n", + " 24,\n", + " 25,\n", + " 26,\n", + " 27,\n", + " 28,\n", + " 29,\n", + " 30,\n", + " 31,\n", + " 32,\n", + " 33,\n", + " 34,\n", + " 35,\n", + " 36,\n", + " 38,\n", + " 40,\n", + " 41,\n", + " 42,\n", + " 43,\n", + " 44,\n", + " 45,\n", + " 46,\n", + " 47,\n", + " 48,\n", + " 50,\n", + " 51,\n", + " 53,\n", + " 54,\n", + " 55,\n", + " 56,\n", + " 57,\n", + " 58,\n", + " 59,\n", + " 60,\n", + " 61,\n", + " 62,\n", + " 63,\n", + " 64,\n", + " 65,\n", + " 66,\n", + " 67,\n", + " 68,\n", + " 69,\n", + " 70,\n", + " 71,\n", + " 72,\n", + " 73,\n", + " 74,\n", + " 75,\n", + " 76,\n", + " 77,\n", + " 78,\n", + " 80,\n", + " 81,\n", + " 82,\n", + " 83,\n", + " 84,\n", + " 85,\n", + " 86,\n", + " 87,\n", + " 89,\n", + " 90,\n", + " 91,\n", + " 92,\n", + " 93,\n", + " 94,\n", + " 95,\n", + " 96,\n", + " 97,\n", + " 98,\n", + " 99,\n", + " 100}" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set3.union(set4, set5)" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{0,\n", + " 1,\n", + " 2,\n", + " 3,\n", + " 4,\n", + " 5,\n", + " 6,\n", + " 7,\n", + " 8,\n", + " 10,\n", + " 11,\n", + " 12,\n", + " 13,\n", + " 14,\n", + " 15,\n", + " 18,\n", + " 19,\n", + " 20,\n", + " 21,\n", + " 22,\n", + " 23,\n", + " 24,\n", + " 25,\n", + " 26,\n", + " 27,\n", + " 28,\n", + " 29,\n", + " 30,\n", + " 31,\n", + " 32,\n", + " 33,\n", + " 34,\n", + " 35,\n", + " 36,\n", + " 38,\n", + " 40,\n", + " 41,\n", + " 42,\n", + " 43,\n", + " 44,\n", + " 45,\n", + " 46,\n", + " 47,\n", + " 48,\n", + " 50,\n", + " 51,\n", + " 53,\n", + " 54,\n", + " 55,\n", + " 56,\n", + " 57,\n", + " 58,\n", + " 59,\n", + " 60,\n", + " 61,\n", + " 62,\n", + " 63,\n", + " 64,\n", + " 65,\n", + " 66,\n", + " 67,\n", + " 68,\n", + " 69,\n", + " 70,\n", + " 71,\n", + " 72,\n", + " 73,\n", + " 74,\n", + " 75,\n", + " 76,\n", + " 77,\n", + " 78,\n", + " 80,\n", + " 81,\n", + " 82,\n", + " 83,\n", + " 84,\n", + " 85,\n", + " 86,\n", + " 87,\n", + " 89,\n", + " 90,\n", + " 91,\n", + " 92,\n", + " 93,\n", + " 94,\n", + " 95,\n", + " 96,\n", + " 97,\n", + " 98,\n", + " 99,\n", + " 100}" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set1.union(set2)" + ] + }, + { + "cell_type": "code", + "execution_count": 98, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set3 == set1" ] }, { @@ -263,11 +691,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 111, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 111, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set1\n", + "set1.pop()" + ] + }, + { + "cell_type": "code", + "execution_count": 112, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{13, 14, 15, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 38, 40, 41, 43, 44, 45, 46, 47, 48, 50, 51, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 64, 65, 67, 68, 69, 70, 72, 73, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 86, 89, 90, 92, 93, 94, 95, 96, 97, 98, 99, 100}\n" + ] + } + ], "source": [ - "# Your code here\n" + "print(set1)" ] }, { @@ -283,11 +742,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 114, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{13, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 30, 32, 33, 34, 35, 36, 38, 40, 43, 44, 45, 46, 47, 48, 50, 53, 54, 55, 56, 57, 58, 62, 63, 64, 65, 67, 68, 70, 72, 73, 75, 76, 77, 78, 80, 82, 83, 84, 85, 86, 90, 92, 93, 94, 95, 96, 97, 98, 100}\n" + ] + } + ], "source": [ - "# Your code here\n" + "list_to_remove = [1, 9, 11, 19, 21, 29, 31, 39, 41, 49, 51, 59, 61, 69, 71, 79, 81, 89, 91, 99]\n", + "\n", + "for l in list_to_remove:\n", + " if l in set1:\n", + " set1.remove(l)\n", + " \n", + " \n", + "print(set1)" ] } ], @@ -307,7 +781,49 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.3" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false } }, "nbformat": 4, diff --git a/your-code/challenge-3.ipynb b/your-code/challenge-3.ipynb index 74d65e0..507019a 100755 --- a/your-code/challenge-3.ipynb +++ b/your-code/challenge-3.ipynb @@ -21,11 +21,11 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "dict1 = {\"Penelope\": 178, \"Arnau\": 172, \"Marta\": 175}" ] }, { @@ -37,11 +37,23 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 6, "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": [ - "# Your code here\n" + "print(dict1.keys())\n", + "print(dict1.values())\n", + "print(dict1.items())\n" ] }, { @@ -53,11 +65,20 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175, 'Carlos': 174}\n" + ] + } + ], "source": [ - "# Your code here\n" + "dict1[\"Carlos\"] = 174\n", + "print(dict1)" ] }, { @@ -69,11 +90,21 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Penelope': 178, 'Arnau': 172, 'Marta': 175}\n" + ] + } + ], "source": [ - "# Your code here\n" + "\n", + "del dict1[\"Carlos\"]\n", + "print(dict1)" ] }, { @@ -87,7 +118,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ @@ -121,11 +152,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" + ] + } + ], "source": [ - "# Your code here\n" + "keys = list(word_freq.keys())\n", + "keys.sort()\n", + "print(keys)" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'a': 8, 'about': 1, 'all': 1, 'although': 3, 'and': 23, 'are': 1, 'at': 1, 'baby': 14, 'backseat': 1, 'bag': 1, 'bar': 1, 'be': 16, 'bedsheets': 3, 'begin': 1, 'best': 1, 'body': 17, 'boy': 2, 'brand': 6, 'can': 1, 'chance': 1, 'club': 1, 'come': 37, 'conversation': 1, 'crazy': 2, 'dance': 1, 'date': 1, 'day': 6, 'discovering': 6, 'do': 3, 'doing': 2, \"don't\": 2, 'drinking': 1, 'driver': 1, 'eat': 1, 'every': 6, 'falling': 3, 'family': 1, 'fast': 1, 'fill': 2, 'find': 1, 'first': 1, 'follow': 6, 'for': 3, 'friends': 1, 'get': 1, 'girl': 2, 'give': 1, 'go': 2, 'going': 1, 'grab': 2, 'hand': 1, 'handmade': 2, 'heart': 3, 'hours': 2, 'how': 1, 'i': 6, \"i'll\": 1, \"i'm\": 23, 'in': 27, 'is': 5, \"isn't\": 1, 'it': 1, 'jukebox': 1, 'just': 1, 'kiss': 1, 'know': 2, 'last': 3, 'lead': 6, 'leave': 1, 'let': 1, \"let's\": 2, 'like': 10, 'love': 25, 'lover': 1, 'magnet': 3, 'make': 1, 'man': 1, 'may': 2, 'me': 10, 'mind': 2, 'much': 2, 'my': 33, 'new': 6, 'night': 3, 'not': 2, 'now': 11, 'of': 6, 'okay': 1, 'on': 40, 'one': 1, 'our': 1, 'out': 1, 'over': 1, 'place': 1, 'plate': 1, 'play': 1, 'pull': 3, 'push': 3, 'put': 3, 'radio': 1, 'room': 3, 'say': 2, 'shape': 6, 'shots': 1, 'singing': 2, 'slow': 1, 'smell': 3, 'so': 2, 'somebody': 2, 'something': 6, 'sour': 1, 'start': 2, 'stop': 1, 'story': 1, 'sweet': 1, 'table': 1, 'take': 1, 'talk': 4, 'taxi': 1, 'tell': 1, 'that': 2, 'the': 18, 'then': 3, 'thrifty': 1, 'to': 2, 'too': 5, 'trust': 1, 'up': 3, 'van': 1, 'waist': 2, 'want': 2, 'was': 2, 'we': 7, \"we're\": 1, 'week': 1, 'were': 3, 'where': 1, 'with': 22, 'you': 16, 'your': 21}\n" + ] + } + ], + "source": [ + "word_freq2 = dict()\n", + "\n", + "for k in keys:\n", + " if k in word_freq.keys():\n", + " word_freq2.update({k:word_freq.get(k)})\n", + " \n", + "print(word_freq2)" ] }, { @@ -162,11 +226,45 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 77, "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" + "import operator\n", + "sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))\n", + "print(sorted_tups)" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "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": [ + "word_freq2 = dict()\n", + "for s in sorted_tups:\n", + " word_freq2.update({s})\n", + " \n", + "print(word_freq2)\n", + " \n", + " \n", + " " ] } ], @@ -186,7 +284,49 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.3" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false } }, "nbformat": 4,