From d04a267bab6b7f0406db706d3948747b615a2884 Mon Sep 17 00:00:00 2001 From: kodimanpr Date: Wed, 4 Dec 2024 12:43:21 -0400 Subject: [PATCH] Update main.ipynb Lab for Map-filter-reduce by Larry Davila --- your-code/main.ipynb | 218 +++++++++++++++++++++++++++++++++---------- 1 file changed, 167 insertions(+), 51 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 9f0e67b..e55c473 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -48,9 +48,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "13637" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "len(prophet)" ] @@ -66,11 +77,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "outputs": [ + { + "data": { + "text/plain": [ + "13069" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# your code here\n", + "prophet_clean=prophet[568:] # Slicing process to remove the first 568 words\n", + "\n", + "len(prophet_clean) # Confirm the total words count after cleaning " ] }, { @@ -82,11 +107,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['PROPHET\\n\\n|Almustafa,', 'the{7}', 'chosen', 'and', 'the\\nbeloved,', 'who', 'was', 'a', 'dawn', 'unto']\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "print(prophet_clean[:10])" ] }, { @@ -100,7 +134,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -114,16 +148,26 @@ " Output: 'the'\n", " '''\n", " \n", - " # your code here" + " # your code here\n", + " return x.split('{')[0]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "print(reference('the{7}')) \n" ] }, { @@ -135,11 +179,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['PROPHET\\n\\n|Almustafa,', 'the', 'chosen', 'and', 'the\\nbeloved,', 'who', 'was', 'a', 'dawn', 'unto']\n" + ] + } + ], + "source": [ + "# your code here\n", + "prophet_reference = list(map(reference, prophet_clean))\n", + "\n", + "print(prophet_reference[:10])" ] }, { @@ -151,7 +206,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -165,7 +220,8 @@ " Output: ['the', 'beloved']\n", " '''\n", " \n", - " # your code here" + " # your code here\n", + " return x.split('\\n')" ] }, { @@ -177,13 +233,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "scrolled": true }, - "outputs": [], - "source": [ - "# your code here" + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['PROPHET', '', '|Almustafa,'], ['the'], ['chosen'], ['and'], ['the', 'beloved,'], ['who'], ['was'], ['a'], ['dawn'], ['unto']]\n" + ] + } + ], + "source": [ + "# your code here\n", + "prophet_line = list(map(line_break, prophet_reference))\n", + "\n", + "print(prophet_line[:10])" ] }, { @@ -195,21 +262,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ - "prophet_flat = [i for sub in prophet_line for i in sub]\n", - "prophet_flat" + "prophet_flat = [i for sub in prophet_line for i in sub]\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['PROPHET', '', '|Almustafa,', 'the', 'chosen', 'and', 'the', 'beloved,', 'who', 'was']\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "print(prophet_flat[:10])" ] }, { @@ -223,7 +298,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -244,7 +319,8 @@ " \n", " word_list = ['and', 'the', 'a', 'an']\n", " \n", - " # your code here" + " # your code here\n", + " return x not in word_list" ] }, { @@ -256,13 +332,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": { "scrolled": true }, - "outputs": [], - "source": [ - "# your code here" + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['PROPHET', '', '|Almustafa,', 'chosen', 'beloved,', 'who', 'was', 'dawn', 'unto', 'his', 'own', 'day,', 'had', 'waited', 'twelve', 'years', 'in', 'city', 'of', 'Orphalese', 'for', 'his', 'ship', 'that', 'was', 'to', 'return', 'bear', 'him', 'back', 'to', 'isle', 'of', 'his', 'birth.', '', 'And', 'in']\n" + ] + } + ], + "source": [ + "# your code here\n", + "prophet_filter=list(filter(word_filter, prophet_flat))\n", + "\n", + "print(prophet_filter[:38])\n" ] }, { @@ -276,15 +363,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['PROPHET', '', '|Almustafa,', 'chosen', 'beloved,', 'who', 'was', 'dawn', 'unto', 'his', 'own', 'day,', 'had', 'waited', 'twelve', 'years', 'in', 'city', 'of', 'Orphalese', 'for', 'his', 'ship', 'that', 'was', 'to', 'return', 'bear', 'him', 'back', 'to', 'isle', 'of', 'his', 'birth.', '', 'in', 'twelfth']\n" + ] + } + ], "source": [ "def word_filter_case(x):\n", " \n", " word_list = ['and', 'the', 'a', 'an']\n", " \n", - " # your code here" + " # your code here\n", + " return x.lower() not in word_list\n", + "\n", + "\n", + "\n", + "\n", + "prophet_filter_case=list(filter(word_filter_case, prophet_flat))\n", + "\n", + "print(prophet_filter_case[:38])\n" ] }, { @@ -300,7 +403,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ @@ -314,18 +417,20 @@ " Output: 'John Smith'\n", " '''\n", " \n", - " # your code here" + " # your code here\n", + " return a+' '+b" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": { "scrolled": true }, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "from functools import reduce" ] }, { @@ -337,17 +442,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PROPHET |Almustafa, chosen beloved, who was dawn unto his own day, had waited twelve years in city \n" + ] + } + ], + "source": [ + "# your code here\n", + "prophet_string=reduce(concat_space, prophet_filter)\n", + "\n", + "print(prophet_string[:100])" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -361,7 +477,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.0" } }, "nbformat": 4,