From 3946498c8e0963c42a06295e30906847a6585c02 Mon Sep 17 00:00:00 2001 From: karthik-aru Date: Thu, 14 Jan 2021 16:34:16 +0100 Subject: [PATCH] Solved --- your-code/main.ipynb | 189 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 152 insertions(+), 37 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 54a8b65..3affb30 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -32,7 +32,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [ @@ -40,7 +40,7 @@ "\n", "location = '../data/58585-0.txt'\n", "with open(location, 'r', encoding=\"utf8\") as f:\n", - " prophet = f.read().split(' ')" + " prophet = f.read().split(' ')\n" ] }, { @@ -54,11 +54,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 61, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "\n", + "prophet_clean = prophet[568:]\n" ] }, { @@ -70,11 +72,34 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['PROPHET\\n\\n|Almustafa,',\n", + " 'the{7}',\n", + " 'chosen',\n", + " 'and',\n", + " 'the\\nbeloved,',\n", + " 'who',\n", + " 'was',\n", + " 'a',\n", + " 'dawn',\n", + " 'unto',\n", + " 'his']" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# your code here\n", + "\n", + "prophet_clean[:11]" ] }, { @@ -88,7 +113,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 63, "metadata": {}, "outputs": [], "source": [ @@ -102,7 +127,12 @@ " Output: 'the'\n", " '''\n", " \n", - " # your code here" + " # your code here\n", + " \n", + " try:\n", + " return x[:x.index('{')]\n", + " except:\n", + " return x\n" ] }, { @@ -114,11 +144,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 64, + "metadata": {}, + "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", + "\n", + "prophet_reference = list(map(reference, prophet_clean))\n", + "\n", + "print(prophet_reference[:10])" ] }, { @@ -130,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "metadata": {}, "outputs": [], "source": [ @@ -144,7 +186,11 @@ " Output: ['the', 'beloved']\n", " '''\n", " \n", - " # your code here" + " # your code here \n", + " try:\n", + " return x.split(\"\\n\")\n", + " except:\n", + " return x" ] }, { @@ -156,11 +202,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "\n", + "prophet_line = list(map(line_break, prophet_reference))\n" ] }, { @@ -172,11 +220,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 67, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['PROPHET', '', '|Almustafa,', 'the', 'chosen', 'and', 'the', 'beloved,', 'who', 'was', 'a', 'dawn', 'unto', 'his', 'own']\n" + ] + } + ], + "source": [ + "from functools import reduce\n", + "# your code here\n", + "\n", + "prophet_flat = reduce(lambda x,y: x+y, prophet_line)\n", + "\n", + "print(prophet_flat[:15])" ] }, { @@ -190,7 +251,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, "outputs": [], "source": [ @@ -211,7 +272,9 @@ " \n", " word_list = ['and', 'the', 'a', 'an']\n", " \n", - " # your code here" + " # your code here\n", + " \n", + " return not x in word_list" ] }, { @@ -221,6 +284,25 @@ "Use the `filter()` function to filter out the words speficied in the `word_filter()` function. Store the filtered list in the variable `prophet_filter`." ] }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['PROPHET', '', '|Almustafa,', 'chosen', 'beloved,', 'who', 'was', 'dawn', 'unto', 'his', 'own', 'day,', 'had', 'waited', 'twelve']\n" + ] + } + ], + "source": [ + "prophet_filter = list(filter(word_filter, prophet_flat))\n", + "\n", + "print(prophet_filter[:15])" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -232,7 +314,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "metadata": {}, "outputs": [], "source": [ @@ -240,7 +322,28 @@ " \n", " word_list = ['and', 'the', 'a', 'an']\n", " \n", - " # your code here" + " # your code here\n", + " \n", + " return not x.lower() in word_list" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['PROPHET', '', '|Almustafa,', 'chosen', 'beloved,', 'who', 'was', 'dawn', 'unto', 'his', 'own', 'day,', 'had', 'waited', 'twelve']\n" + ] + } + ], + "source": [ + "prophet_filter = list(filter(word_filter_case, prophet_flat))\n", + "\n", + "print(prophet_filter[:15])" ] }, { @@ -256,7 +359,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "metadata": {}, "outputs": [], "source": [ @@ -270,7 +373,9 @@ " Output: 'John Smith'\n", " '''\n", " \n", - " # your code here" + " # your code here\n", + " \n", + " return a + \" \" + b" ] }, { @@ -282,11 +387,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 76, + "metadata": {}, + "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 year, o\n" + ] + } + ], + "source": [ + "# your code here\n", + "\n", + "prophet_string = reduce(concat_space, prophet_filter)\n" ] }, { @@ -412,7 +527,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.6" } }, "nbformat": 4,