From 717849938298eadd16d210189fde3e1c0fa392f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Garc=C3=ADa?= Date: Wed, 11 Oct 2023 16:42:31 +0200 Subject: [PATCH 1/3] Lab Comprehension --- your-code/main.ipynb | 125 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 101 insertions(+), 24 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index a9c7a0c..94b097e 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -27,10 +27,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], - "source": [] + "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": [ + "lista = [i for i in range(1, 51)]\n", + "print(lista)" + ] }, { "cell_type": "markdown", @@ -41,10 +52,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], - "source": [] + "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": [ + "#lista = []\n", + "#for i in range (2, 201, 2):\n", + "# lista.append(i)\n", + "#print(lista)\n", + "\n", + "lista = [i for i in range(2, 201, 2)]\n", + "print(lista)" + ] }, { "cell_type": "markdown", @@ -55,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -73,10 +100,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], - "source": [] + "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": [ + "lista = [j for i in a for j in i]\n", + "print(lista)" + ] }, { "cell_type": "markdown", @@ -87,10 +125,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], - "source": [] + "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": [ + "lista = [j for i in a for j in i if j >= 0.5]\n", + "print(lista)" + ] }, { "cell_type": "markdown", @@ -101,7 +150,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -126,7 +175,10 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "lista = [k for i in b for j in i for k in j]\n", + "print(lista)" + ] }, { "cell_type": "markdown", @@ -137,10 +189,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.08147297, 0.06833034, 0.30296619, 0.45850679, 0.11434044, 0.10708681, 0.47984544, 0.23760688]\n", + "[0.08147297, 0.06833034, 0.30296619, 0.45850679, 0.11434044, 0.10708681, 0.47984544, 0.23760688]\n" + ] + } + ], + "source": [ + "lista = [j[-1] for i in b for j in i if j[-1] <= 0.5]\n", + "print(lista)" + ] }, { "cell_type": "markdown", @@ -151,10 +215,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['sample_file_0', 'sample_file_1', 'sample_file_2', 'sample_file_3', 'sample_file_4', 'sample_file_5', 'sample_file_6', 'sample_file_7', 'sample_file_8', 'sample_file_9']\n" + ] + } + ], + "source": [ + "os.chdir(\"../data\")\n", + "path = os.getcwd()\n", + "data = [i[:-4] for i in os.listdir(path) if i.endswith(\".csv\")]\n", + "print(data)" + ] }, { "cell_type": "markdown", @@ -193,7 +270,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -207,7 +284,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.11.3" } }, "nbformat": 4, From cc2ba09ff1c4817204615e8e37bf94f56bd05db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Garc=C3=ADa?= Date: Wed, 11 Oct 2023 16:49:32 +0200 Subject: [PATCH 2/3] Lab Comprehension cleaned --- your-code/main.ipynb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 94b097e..fa12be6 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -64,11 +64,6 @@ } ], "source": [ - "#lista = []\n", - "#for i in range (2, 201, 2):\n", - "# lista.append(i)\n", - "#print(lista)\n", - "\n", "lista = [i for i in range(2, 201, 2)]\n", "print(lista)" ] From fe2b94bfc484846d97989ac214325af52d4c2246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Garc=C3=ADa?= Date: Wed, 11 Oct 2023 18:08:47 +0200 Subject: [PATCH 3/3] 3 katas --- your-code/main.ipynb | 103 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index fa12be6..ae0183a 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -261,6 +261,109 @@ "**Advanced**\n", "- [Queue time counter](https://www.codewars.com/kata/queue-time-counter)" ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[-1, -2, -3, -4, -5]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Given a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives.\n", + "def invert(lst):\n", + " return [-i for i in lst]\n", + "\n", + "invert([1,2,3,4,5])" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "50" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Complete the square sum function so that it squares each number passed into it and then sums the results together.\n", + "def square_sum(numbers):\n", + " return sum(i**2 for i in numbers)\n", + "\n", + "square_sum([0, 3, 4, 5])" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3]" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Given a non-negative integer, return an array / a list of the individual digits in order.\n", + "def digitize(n):\n", + " return [int(i) for i in str(n)]\n", + "\n", + "digitize(123)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 123]" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out.\n", + "def filter_list(l):\n", + " return [i for i in l if str(i).isdigit() and i != str(i)]\n", + " \n", + "filter_list([1, 2, 'aasf', '1', '123', 123])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {