From 501497cdc63e5b7c973bccdc192473a10ecf3595 Mon Sep 17 00:00:00 2001 From: Andre Santa Clara Date: Sun, 25 Oct 2020 19:46:35 +0100 Subject: [PATCH 1/2] addlab --- your-code/main.ipynb | 258 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 223 insertions(+), 35 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 7afceca..8b285dc 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -11,11 +11,11 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "import os;" + "import os" ] }, { @@ -27,11 +27,23 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 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]\n" + ] + } + ], "source": [ - "# your code here " + "# your code here \n", + "\n", + "number = [x for x in range(1,51)]\n", + "\n", + "print(number)" ] }, { @@ -43,11 +55,42 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200]\n" + ] + } + ], "source": [ - "# your code here " + "# your code here \n", + "\n", + "number = [2*x for x in range(1,101)]\n", + "\n", + "print(number)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200]\n" + ] + } + ], + "source": [ + "number = [x for x in range(1,201) if x % 2 == 0]\n", + "\n", + "print(number)" ] }, { @@ -59,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -77,11 +120,23 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.84062117, 0.48006452, 0.7876326, 0.77109654, 0.44409793, 0.09014516, 0.81835917, 0.87645456, 0.7066597, 0.09610873, 0.41247947, 0.57433389, 0.29960807, 0.42315023, 0.34452557, 0.4751035, 0.17003563, 0.46843998, 0.92796258, 0.69814654, 0.41290051, 0.19561071, 0.16284783, 0.97016248, 0.71725408, 0.87702738, 0.31244595, 0.76615487, 0.20754036, 0.57871812, 0.07214068, 0.40356048, 0.12149553, 0.53222417, 0.9976855, 0.12536346, 0.80930099, 0.50962849, 0.94555126, 0.33364763]\n" + ] + } + ], "source": [ - "# your code here " + "# your code here \n", + "\n", + "new_array = [x for row in a for x in row]\n", + "\n", + "print(new_array)" ] }, { @@ -93,11 +148,23 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.84062117, 0.7876326, 0.77109654, 0.81835917, 0.87645456, 0.7066597, 0.57433389, 0.92796258, 0.69814654, 0.97016248, 0.71725408, 0.87702738, 0.76615487, 0.57871812, 0.53222417, 0.9976855, 0.80930099, 0.50962849, 0.94555126]\n" + ] + } + ], "source": [ - "# your code here " + "# your code here \n", + "\n", + "new_array1 = [x for row in a for x in row if x >= 0.5]\n", + "\n", + "print(new_array1)" ] }, { @@ -109,7 +176,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -131,11 +198,23 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.55867166, 0.06210792, 0.08147297, 0.82579068, 0.91512478, 0.06833034, 0.05440634, 0.65857693, 0.30296619, 0.06769833, 0.96031863, 0.51293743, 0.09143215, 0.71893382, 0.45850679, 0.58256464, 0.59005654, 0.56266457, 0.71600294, 0.87392666, 0.11434044, 0.8694668, 0.65669313, 0.10708681, 0.07529684, 0.46470767, 0.47984544, 0.65368638, 0.14901286, 0.23760688]\n" + ] + } + ], "source": [ - "# your code here " + "# your code here \n", + "\n", + "new_array2 = [x for row in b for sub_row in row for x in sub_row] \n", + "\n", + "print(new_array2)" ] }, { @@ -147,11 +226,23 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.06210792, 0.08147297, 0.06833034, 0.05440634, 0.30296619, 0.06769833, 0.09143215, 0.45850679, 0.11434044, 0.10708681, 0.07529684, 0.46470767, 0.47984544, 0.14901286, 0.23760688]\n" + ] + } + ], "source": [ - "# your code here " + "# your code here \n", + "\n", + "new_array3 = [x for row in b for sub_row in row for x in sub_row if x <= 0.5] \n", + "\n", + "print(new_array3)\n" ] }, { @@ -163,11 +254,29 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "FileNotFoundError", + "evalue": "[Errno 2] No such file or directory: './data'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mFileNotFoundError\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 5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0misfile\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mjoin\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0monlyfiles\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mlistdir\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"./data\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misfile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"./data\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: './data'" + ] + } + ], "source": [ - "# your code here " + "# your code here \n", + "\n", + "from os import listdir\n", + "\n", + "from os.path import isfile, join\n", + "\n", + "onlyfiles = [f for f in listdir(\"./data\") if isfile(join(\"./data\", f))]" ] }, { @@ -196,7 +305,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 78, "metadata": {}, "outputs": [], "source": [ @@ -206,11 +315,49 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 131, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'bananas': 2, 'ice-cream': 1, 'carrots': 5, 'cookies': 9, 'guanciale': 7, 'pasta': 2}\n" + ] + } + ], + "source": [ + "# your code here\n", + "\n", + "shopping_dict = zip(fruits,quantities)\n", + "new_shopping_dict = dict(shopping_dict)\n", + "print(new_shopping_dict)" + ] + }, + { + "cell_type": "code", + "execution_count": 132, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "shopping_dict1 = {key: value for key, value in zip(fruits, quantities)}" + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'bananas': 2, 'ice-cream': 1, 'carrots': 5, 'cookies': 9, 'guanciale': 7, 'pasta': 2}\n" + ] + } + ], + "source": [ + "print(shopping_dict1)" ] }, { @@ -227,11 +374,20 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 137, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'bananas': 4, 'ice-cream': 2, 'carrots': 10, 'cookies': 18, 'guanciale': 14, 'pasta': 4}\n" + ] + } + ], "source": [ - "# your code here" + "shopping_dict2 = {key: value*2 for key, value in shopping_dict1.items()}\n", + "print(shopping_dict2)" ] }, { @@ -248,11 +404,43 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 145, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'bananas': 4, 'ice-cream': 2, 'carrots': 10, 'cookies': '8', 'guanciale': '8', 'pasta': 4}\n" + ] + } + ], + "source": [ + "# your code here\n", + "\n", + "cheap_shopping_dict = {key: (\"8\" if value > 10 else value) for key, value in shopping_dict2.items()}\n", + "print(cheap_shopping_dict)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'x' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mNameError\u001b[0m: name 'x' is not defined" + ] + } + ], "source": [ - "# your code here" + "x" ] }, { @@ -313,7 +501,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.8.3" } }, "nbformat": 4, From 29b342c9b58a2fceb8521ace901250f657f5d09d Mon Sep 17 00:00:00 2001 From: Andre Santa Clara Date: Sun, 25 Oct 2020 19:47:26 +0100 Subject: [PATCH 2/2] labs --- your-code/main.ipynb | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 8b285dc..8618ad6 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -424,24 +424,10 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'x' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mNameError\u001b[0m: name 'x' is not defined" - ] - } - ], - "source": [ - "x" - ] + "outputs": [], + "source": [] }, { "cell_type": "markdown",