From f6bc044ac51f18bd4f775a1abb46e4d61aca0a61 Mon Sep 17 00:00:00 2001 From: sara-pena Date: Sun, 25 Oct 2020 17:56:16 +0100 Subject: [PATCH] Challenge solved --- ...ain.ipynb => Lab list comprehension.ipynb} | 115 ++++++++++++++---- 1 file changed, 88 insertions(+), 27 deletions(-) rename your-code/{main.ipynb => Lab list comprehension.ipynb} (71%) diff --git a/your-code/main.ipynb b/your-code/Lab list comprehension.ipynb similarity index 71% rename from your-code/main.ipynb rename to your-code/Lab list comprehension.ipynb index 7afceca..d3ef3b7 100755 --- a/your-code/main.ipynb +++ b/your-code/Lab list comprehension.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -27,11 +27,11 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# your code here " + "print(list(range(1, 51)))" ] }, { @@ -43,11 +43,12 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# your code here " + "# your code here \n", + "print(list(range(2, 201, 2)))" ] }, { @@ -59,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ @@ -77,11 +78,19 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 47, "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 " + "b = print([numero for subl in a for numero in subl])" ] }, { @@ -93,11 +102,11 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# your code here " + "c = print([numero for subl in a for numero in subl if numero >= 0.5 ])" ] }, { @@ -109,11 +118,11 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "b = [[[0.55867166, 0.06210792, 0.08147297],\n", + "e = [[[0.55867166, 0.06210792, 0.08147297],\n", " [0.82579068, 0.91512478, 0.06833034]],\n", "\n", " [[0.05440634, 0.65857693, 0.30296619],\n", @@ -131,11 +140,46 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0.55867166, 0.06210792, 0.08147297], [0.82579068, 0.91512478, 0.06833034]]\n" + ] + } + ], + "source": [ + "print(e[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "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 " + "# va de afuera hacia adentro\n", + "\n", + "f = print([numero for subl_1 in e for subl_2 in subl_1 for numero in subl_2])\n", + "\n", + "#como funciona:\n", + "#flat_array_1 = [numero for subl_1 in e for subl_2 in subl_1]\n", + "#flat_array_2 = [numero for sub2 in flat_array_1 for numero in sub2 ]\n", + "\n", + "\n", + "#print(\"flat1\", flat_array_1)\n", + "#print(\"flat2\", flat_array_2)\n" ] }, { @@ -147,11 +191,19 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.08147297, 0.06833034, 0.30296619, 0.45850679, 0.11434044, 0.10708681, 0.47984544, 0.23760688]\n" + ] + } + ], "source": [ - "# your code here " + "g = print([subl_2[-1] for subl_1 in e for subl_2 in subl_1 if subl_2[-1] <= 0.5])" ] }, { @@ -163,11 +215,20 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 45, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['sample_file_1.csv', 'sample_file_0.csv', 'sample_file_2.csv', 'sample_file_3.csv', 'sample_file_7.csv', 'sample_file_6.csv', 'sample_file_4.csv', 'sample_file_5.csv', 'sample_file_8.csv', 'sample_file_9.csv']\n" + ] + } + ], "source": [ - "# your code here " + "print([f for f in os.listdir(\"/Users/Sara/Documents/Bootcamp/Week1/Day5/lab-list-comprehensions/data/\") if os.path.isfile(os.path.join(dir,f)) and f.endswith(\".csv\")])\n", + "# os.path.join joins a directory and a filename into a path. You can also split a path name into directory and file with os.path.split(), and you can split a filename with extension into filename and extension with os.path.splitext()" ] }, { @@ -196,7 +257,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -206,7 +267,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -227,7 +288,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -248,7 +309,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -313,7 +374,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.8.3" } }, "nbformat": 4,