diff --git a/module-1/advanced-regex/your-code/main.ipynb b/module-1/advanced-regex/your-code/main.ipynb index b898da50..36f80b43 100644 --- a/module-1/advanced-regex/your-code/main.ipynb +++ b/module-1/advanced-regex/your-code/main.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -36,10 +36,43 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['i',\n", + " 'i',\n", + " 'o',\n", + " 'i',\n", + " 'o',\n", + " 'e',\n", + " 'a',\n", + " 'e',\n", + " 'e',\n", + " 'e',\n", + " 'i',\n", + " 'a',\n", + " 'o',\n", + " 'o',\n", + " 'u',\n", + " 'e',\n", + " 'o',\n", + " 'o',\n", + " 'e',\n", + " 'i',\n", + " 'i']" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[i for i in text if i in r'aeiou']\n" + ] }, { "cell_type": "markdown", @@ -50,19 +83,166 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ - "text = \"The puppy saw all the rest of the puppies playing and wanted to join them. I saw this and wanted a puppy of my own!\"" + "puppy_text = \"The puppy saw all the rest of the puppies playing and wanted to join them. I saw this and wanted a puppy of my own!\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['p',\n", + " 'u',\n", + " 'p',\n", + " 'p',\n", + " 'y',\n", + " 'p',\n", + " 'u',\n", + " 'p',\n", + " 'p',\n", + " 'p',\n", + " 'y',\n", + " 'p',\n", + " 'u',\n", + " 'p',\n", + " 'p',\n", + " 'y',\n", + " 'y']" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[i for i in text if i in r'puppy']" + ] + }, + { + "cell_type": "code", + "execution_count": 29, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "regex_puppy = r'puppy|puppies'" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "text_puppy=text.split()" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['The',\n", + " 'puppy',\n", + " 'saw',\n", + " 'all',\n", + " 'the',\n", + " 'rest',\n", + " 'of',\n", + " 'the',\n", + " 'puppies',\n", + " 'playing',\n", + " 'and',\n", + " 'wanted',\n", + " 'to',\n", + " 'join',\n", + " 'them.',\n", + " 'I',\n", + " 'saw',\n", + " 'this',\n", + " 'and',\n", + " 'wanted',\n", + " 'a',\n", + " 'puppy',\n", + " 'of',\n", + " 'my',\n", + " 'own!']" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "text_puppy" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['puppy', 'puppies', 'puppy']" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "re.findall(regex_puppy,text)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "count = 0\n", + "\n", + "for i in text_puppy:\n", + " if i in regex_puppy:\n", + " count=count + 1\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "count" + ] }, { "cell_type": "markdown", @@ -73,19 +253,118 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ - "text = \"I ran the relay race the only way I knew how to run it.\"" + "text_run = \"I ran the relay race the only way I knew how to run it.\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "regex_run = r'run|ran'" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "split_run = text_run.split() " + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['I',\n", + " 'ran',\n", + " 'the',\n", + " 'relay',\n", + " 'race',\n", + " 'the',\n", + " 'only',\n", + " 'way',\n", + " 'I',\n", + " 'knew',\n", + " 'how',\n", + " 'to',\n", + " 'run',\n", + " 'it.']" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "split_run" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['ran', 'run']" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[i for i in split_run if i in regex_run]" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "count=0\n", + "\n", + "for i in split_run:\n", + " if i in regex_run:\n", + " count=count+1" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "count" + ] }, { "cell_type": "markdown", @@ -101,6 +380,61 @@ "outputs": [], "source": [] }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [], + "source": [ + "text_run = \"I ran the relay race the only way I knew how to run it.\"" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "words_run = text_run.split()" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['ran', 'relay', 'race', 'run']\n" + ] + } + ], + "source": [ + "words = text_run.split()\n", + "list = []\n", + "\n", + "for word in words:\n", + " if re.search(r'r[a-z]*', word):\n", + " list.append(word)\n", + "print(list)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -110,7 +444,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "text = \"Th!s !s a sentence w!th spec!al characters !n !t.\"" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is a sentence with special characters in it.\n" + ] + } + ], + "source": [ + "new_text = print(re.sub('!', 'i', text))\n", + "new_text" + ] + }, + { + "cell_type": "code", + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ @@ -133,13 +494,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "text = \"This sentence has words of varying lengths.\"" ] }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [], + "source": [ + "words = text.split()" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "list = []\n", + "\n", + "for word in words:\n", + " if re.search(r'[a-zA-Z]{5}', word):\n", + " list.append(word)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['sentence', 'words', 'varying', 'lengths.']\n" + ] + } + ], + "source": [ + "print(list)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -156,7 +557,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, "outputs": [], "source": [ @@ -165,10 +566,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bet', 'beat', 'bot', 'bat', 'but', 'bit']" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "re.findall(r'\\bb[a-z]*t\\b', text)" + ] }, { "cell_type": "markdown", @@ -179,7 +593,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, "outputs": [], "source": [ @@ -188,10 +602,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['peaks', 'people', 'realize', 'breathtaking', 'Nearly']" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "re.findall(r'\\b\\w*ea\\w*\\b|\\b\\w*eo\\w*\\b', text)" + ] }, { "cell_type": "markdown", @@ -202,7 +629,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, "outputs": [], "source": [ @@ -211,10 +638,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['T', 'R', 'A', 'L']" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "re.findall(r'[A-Z]', text)" + ] }, { "cell_type": "markdown", @@ -223,6 +663,26 @@ "### 10. Use a regular expression to find and extract all the sets of consecutive capitalized words in the text above." ] }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Teddy', 'Roosevelt', 'Abraham', 'Lincoln']" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "re.findall(r'\\b[A-Z]\\w*\\b', text)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -241,7 +701,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [ @@ -250,10 +710,58 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 63, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "get_quotes = re.findall(r'\"(.*?)\"', text)" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['I will bet you $50 I can get the bartender to give me a free drink.', 'I am in!']\n" + ] + } + ], + "source": [ + "print(get_quotes)" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [], + "source": [ + "first_sentence=get_quotes[0]\n", + "second_sentence=get_quotes[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I will bet you $50 I can get the bartender to give me a free drink.\n", + "I am in!\n" + ] + } + ], + "source": [ + "print(first_sentence)\n", + "print(second_sentence)" + ] }, { "cell_type": "markdown", @@ -264,7 +772,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, "outputs": [], "source": [ @@ -273,10 +781,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['30', '30', '14', '16', '10']" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "re.findall(r'\\b[0-9]+\\b', text)" + ] }, { "cell_type": "markdown", @@ -287,7 +808,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "metadata": {}, "outputs": [], "source": [ @@ -299,10 +820,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['876-93-2289', '098-32-5295']" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "re.findall(r'[0-9]+[-]+[0-9]+[-]+[0-9]+', text)" + ] }, { "cell_type": "markdown", @@ -313,10 +847,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['(847)789-0984', '(987)222-0901']" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "re.findall(r'[(][0-9]+[)]+[0-9]+[-]+[0-9]+', text)" + ] }, { "cell_type": "markdown", @@ -325,6 +872,26 @@ "### 15. Use a regular expression to find and extract all the formatted numbers (both social security and phone) from the text below." ] }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['876-93-2289', '(847)789-0984', '098-32-5295', '(987)222-0901']" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "re.findall(r'[0-9]+-[0-9+-[0-9]+|[(]+[0-9]+[)].*-[0-9]+', text)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -349,7 +916,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.7.7" } }, "nbformat": 4, diff --git a/module-1/map-reduce-filter/your-code/main.ipynb b/module-1/map-reduce-filter/your-code/main.ipynb index 51d50b0d..8fb147e4 100644 --- a/module-1/map-reduce-filter/your-code/main.ipynb +++ b/module-1/map-reduce-filter/your-code/main.ipynb @@ -12,11 +12,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": {}, "outputs": [], "source": [ - "# Import reduce from functools, numpy and pandas" + "# Import reduce from functools, numpy and pandas\n", + "\n", + "from functools import reduce\n", + "import numpy as np\n", + "import pandas as pd\n" ] }, { @@ -32,7 +36,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": {}, "outputs": [], "source": [ @@ -43,6 +47,26 @@ " prophet = f.read().split(' ')" ] }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'\\ufeffThe'" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prophet[0]" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -54,11 +78,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 78, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "\n", + "prophet = prophet[568:]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'PROPHET\\n\\n|Almustafa,'" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prophet[0]" ] }, { @@ -70,11 +116,1052 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 80, "metadata": {}, - "outputs": [], + "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']" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# your code here\n", + "prophet[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "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',\n", + " 'own\\nday,',\n", + " 'had',\n", + " 'waited',\n", + " 'twelve',\n", + " 'years',\n", + " 'in',\n", + " 'the',\n", + " 'city\\nof',\n", + " 'Orphalese',\n", + " 'for',\n", + " 'his',\n", + " 'ship',\n", + " 'that',\n", + " 'was',\n", + " 'to\\nreturn',\n", + " 'and',\n", + " 'bear',\n", + " 'him',\n", + " 'back',\n", + " 'to',\n", + " 'the',\n", + " 'isle',\n", + " 'of\\nhis',\n", + " 'birth.\\n\\nAnd',\n", + " 'in',\n", + " 'the',\n", + " 'twelfth',\n", + " 'year,',\n", + " 'on',\n", + " 'the',\n", + " 'seventh\\nday',\n", + " 'of',\n", + " 'Ielool,',\n", + " 'the',\n", + " 'month',\n", + " 'of',\n", + " 'reaping,',\n", + " 'he\\nclimbed',\n", + " 'the',\n", + " 'hill',\n", + " 'without',\n", + " 'the',\n", + " 'city',\n", + " 'walls\\nand',\n", + " 'looked',\n", + " 'seaward;',\n", + " 'and',\n", + " 'he',\n", + " 'beheld',\n", + " 'his\\nship',\n", + " 'coming',\n", + " 'with',\n", + " 'the',\n", + " 'mist.\\n\\nThen',\n", + " 'the',\n", + " 'gates',\n", + " 'of',\n", + " 'his',\n", + " 'heart',\n", + " 'were',\n", + " 'flung\\nopen,',\n", + " 'and',\n", + " 'his',\n", + " 'joy',\n", + " 'flew',\n", + " 'far',\n", + " 'over',\n", + " 'the',\n", + " 'sea.\\nAnd',\n", + " 'he',\n", + " 'closed',\n", + " 'his',\n", + " 'eyes',\n", + " 'and',\n", + " 'prayed',\n", + " 'in',\n", + " 'the\\nsilences',\n", + " 'of',\n", + " 'his',\n", + " 'soul.\\n\\n*****\\n\\nBut',\n", + " 'as',\n", + " 'he',\n", + " 'descended',\n", + " 'the',\n", + " 'hill,',\n", + " 'a',\n", + " 'sadness\\ncame',\n", + " 'upon',\n", + " 'him,',\n", + " 'and',\n", + " 'he',\n", + " 'thought',\n", + " 'in',\n", + " 'his\\nheart:\\n\\nHow',\n", + " 'shall',\n", + " 'I',\n", + " 'go',\n", + " 'in',\n", + " 'peace',\n", + " 'and',\n", + " 'without\\nsorrow?',\n", + " 'Nay,',\n", + " 'not',\n", + " 'without',\n", + " 'a',\n", + " 'wound',\n", + " 'in',\n", + " 'the\\nspirit',\n", + " 'shall',\n", + " 'I',\n", + " 'leave',\n", + " 'this',\n", + " 'city.',\n", + " '{8}Long\\nwere',\n", + " 'the',\n", + " 'days',\n", + " 'of',\n", + " 'pain',\n", + " 'I',\n", + " 'have',\n", + " 'spent\\nwithin',\n", + " 'its',\n", + " 'walls,',\n", + " 'and',\n", + " 'long',\n", + " 'were',\n", + " 'the\\nnights',\n", + " 'of',\n", + " 'aloneness;',\n", + " 'and',\n", + " 'who',\n", + " 'can',\n", + " 'depart\\nfrom',\n", + " 'his',\n", + " 'pain',\n", + " 'and',\n", + " 'his',\n", + " 'aloneness',\n", + " 'without\\nregret?\\n\\nToo',\n", + " 'many',\n", + " 'fragments',\n", + " 'of',\n", + " 'the',\n", + " 'spirit',\n", + " 'have',\n", + " 'I\\nscattered',\n", + " 'in',\n", + " 'these',\n", + " 'streets,',\n", + " 'and',\n", + " 'too',\n", + " 'many\\nare',\n", + " 'the',\n", + " 'children',\n", + " 'of',\n", + " 'my',\n", + " 'longing',\n", + " 'that',\n", + " 'walk\\nnaked',\n", + " 'among',\n", + " 'these',\n", + " 'hills,',\n", + " 'and',\n", + " 'I',\n", + " 'cannot\\nwithdraw',\n", + " 'from',\n", + " 'them',\n", + " 'without',\n", + " 'a',\n", + " 'burden',\n", + " 'and\\nan',\n", + " 'ache.\\n\\nIt',\n", + " 'is',\n", + " 'not',\n", + " 'a',\n", + " 'garment',\n", + " 'I',\n", + " 'cast',\n", + " 'off',\n", + " 'this\\nday,',\n", + " 'but',\n", + " 'a',\n", + " 'skin',\n", + " 'that',\n", + " 'I',\n", + " 'tear',\n", + " 'with',\n", + " 'my',\n", + " 'own\\nhands.\\n\\nNor',\n", + " 'is',\n", + " 'it',\n", + " 'a',\n", + " 'thought',\n", + " 'I',\n", + " 'leave',\n", + " 'behind',\n", + " 'me,\\nbut',\n", + " 'a',\n", + " 'heart',\n", + " 'made',\n", + " 'sweet',\n", + " 'with',\n", + " 'hunger',\n", + " 'and\\nwith',\n", + " 'thirst.\\n\\n*****\\n\\nYet',\n", + " 'I',\n", + " 'cannot',\n", + " 'tarry',\n", + " 'longer.\\n\\nThe',\n", + " 'sea',\n", + " 'that',\n", + " 'calls',\n", + " 'all',\n", + " 'things',\n", + " 'unto',\n", + " 'her\\ncalls',\n", + " 'me,',\n", + " 'and',\n", + " 'I',\n", + " 'must',\n", + " 'embark.\\n\\nFor',\n", + " 'to',\n", + " 'stay,',\n", + " 'though',\n", + " 'the',\n", + " 'hours',\n", + " 'burn',\n", + " 'in\\nthe',\n", + " 'night,',\n", + " 'is',\n", + " 'to',\n", + " 'freeze',\n", + " 'and',\n", + " 'crystallize\\nand',\n", + " 'be',\n", + " 'bound',\n", + " 'in',\n", + " 'a',\n", + " 'mould.\\n\\nFain',\n", + " 'would',\n", + " 'I',\n", + " 'take',\n", + " 'with',\n", + " 'me',\n", + " 'all',\n", + " 'that',\n", + " 'is\\nhere.',\n", + " 'But',\n", + " 'how',\n", + " 'shall',\n", + " 'I?\\n\\nA',\n", + " 'voice',\n", + " 'cannot',\n", + " 'carry',\n", + " 'the',\n", + " 'tongue',\n", + " 'and\\n{9}the',\n", + " 'lips',\n", + " 'that',\n", + " 'gave',\n", + " 'it',\n", + " 'wings.',\n", + " 'Alone\\nmust',\n", + " 'it',\n", + " 'seek',\n", + " 'the',\n", + " 'ether.\\n\\nAnd',\n", + " 'alone',\n", + " 'and',\n", + " 'without',\n", + " 'his',\n", + " 'nest',\n", + " 'shall',\n", + " 'the\\neagle',\n", + " 'fly',\n", + " 'across',\n", + " 'the',\n", + " 'sun.\\n\\n*****\\n\\nNow',\n", + " 'when',\n", + " 'he',\n", + " 'reached',\n", + " 'the',\n", + " 'foot',\n", + " 'of',\n", + " 'the\\nhill,',\n", + " 'he',\n", + " 'turned',\n", + " 'again',\n", + " 'towards',\n", + " 'the',\n", + " 'sea,\\nand',\n", + " 'he',\n", + " 'saw',\n", + " 'his',\n", + " 'ship',\n", + " 'approaching',\n", + " 'the\\nharbour,',\n", + " 'and',\n", + " 'upon',\n", + " 'her',\n", + " 'prow',\n", + " 'the',\n", + " 'mariners,\\nthe',\n", + " 'men',\n", + " 'of',\n", + " 'his',\n", + " 'own',\n", + " 'land.\\n\\nAnd',\n", + " 'his',\n", + " 'soul',\n", + " 'cried',\n", + " 'out',\n", + " 'to',\n", + " 'them,',\n", + " 'and',\n", + " 'he\\nsaid:\\n\\nSons',\n", + " 'of',\n", + " 'my',\n", + " 'ancient',\n", + " 'mother,',\n", + " 'you',\n", + " 'riders',\n", + " 'of\\nthe',\n", + " 'tides,\\n\\nHow',\n", + " 'often',\n", + " 'have',\n", + " 'you',\n", + " 'sailed',\n", + " 'in',\n", + " 'my',\n", + " 'dreams.\\nAnd',\n", + " 'now',\n", + " 'you',\n", + " 'come',\n", + " 'in',\n", + " 'my',\n", + " 'awakening,',\n", + " 'which\\nis',\n", + " 'my',\n", + " 'deeper',\n", + " 'dream.\\n\\nReady',\n", + " 'am',\n", + " 'I',\n", + " 'to',\n", + " 'go,',\n", + " 'and',\n", + " 'my',\n", + " 'eagerness',\n", + " 'with\\nsails',\n", + " 'full',\n", + " 'set',\n", + " 'awaits',\n", + " 'the',\n", + " 'wind.\\n\\nOnly',\n", + " 'another',\n", + " 'breath',\n", + " 'will',\n", + " 'I',\n", + " 'breathe',\n", + " 'in\\nthis',\n", + " 'still',\n", + " 'air,',\n", + " 'only',\n", + " 'another',\n", + " 'loving',\n", + " 'look\\ncast',\n", + " 'backward,\\n\\nAnd',\n", + " 'then',\n", + " 'I',\n", + " 'shall',\n", + " 'stand',\n", + " 'among',\n", + " 'you,',\n", + " 'a\\nseafarer',\n", + " 'among',\n", + " 'seafarers.',\n", + " '{10}And',\n", + " 'you,\\nvast',\n", + " 'sea,',\n", + " 'sleepless',\n", + " 'mother,\\n\\nWho',\n", + " 'alone',\n", + " 'are',\n", + " 'peace',\n", + " 'and',\n", + " 'freedom',\n", + " 'to',\n", + " 'the\\nriver',\n", + " 'and',\n", + " 'the',\n", + " 'stream,\\n\\nOnly',\n", + " 'another',\n", + " 'winding',\n", + " 'will',\n", + " 'this',\n", + " 'stream\\nmake,',\n", + " 'only',\n", + " 'another',\n", + " 'murmur',\n", + " 'in',\n", + " 'this',\n", + " 'glade,\\n\\nAnd',\n", + " 'then',\n", + " 'shall',\n", + " 'I',\n", + " 'come',\n", + " 'to',\n", + " 'you,',\n", + " 'a\\nboundless',\n", + " 'drop',\n", + " 'to',\n", + " 'a',\n", + " 'boundless',\n", + " 'ocean.\\n\\n*****\\n\\nAnd',\n", + " 'as',\n", + " 'he',\n", + " 'walked',\n", + " 'he',\n", + " 'saw',\n", + " 'from',\n", + " 'afar',\n", + " 'men\\nand',\n", + " 'women',\n", + " 'leaving',\n", + " 'their',\n", + " 'fields',\n", + " 'and',\n", + " 'their\\nvineyards',\n", + " 'and',\n", + " 'hastening',\n", + " 'towards',\n", + " 'the',\n", + " 'city\\ngates.\\n\\nAnd',\n", + " 'he',\n", + " 'heard',\n", + " 'their',\n", + " 'voices',\n", + " 'calling',\n", + " 'his\\nname,',\n", + " 'and',\n", + " 'shouting',\n", + " 'from',\n", + " 'field',\n", + " 'to',\n", + " 'field\\ntelling',\n", + " 'one',\n", + " 'another',\n", + " 'of',\n", + " 'the',\n", + " 'coming',\n", + " 'of',\n", + " 'his\\nship.\\n\\nAnd',\n", + " 'he',\n", + " 'said',\n", + " 'to',\n", + " 'himself:\\n\\nShall',\n", + " 'the',\n", + " 'day',\n", + " 'of',\n", + " 'parting',\n", + " 'be',\n", + " 'the',\n", + " 'day',\n", + " 'of\\ngathering?\\n\\nAnd',\n", + " 'shall',\n", + " 'it',\n", + " 'be',\n", + " 'said',\n", + " 'that',\n", + " 'my',\n", + " 'eve',\n", + " 'was',\n", + " 'in\\ntruth',\n", + " 'my',\n", + " 'dawn?\\n\\nAnd',\n", + " 'what',\n", + " 'shall',\n", + " 'I',\n", + " 'give',\n", + " 'unto',\n", + " 'him',\n", + " 'who',\n", + " 'has\\nleft',\n", + " 'his',\n", + " 'plough',\n", + " 'in',\n", + " 'midfurrow,',\n", + " 'or',\n", + " 'to\\nhim',\n", + " 'who',\n", + " 'has',\n", + " 'stopped',\n", + " 'the',\n", + " 'wheel',\n", + " 'of',\n", + " 'his\\nwinepress?',\n", + " '{11}Shall',\n", + " 'my',\n", + " 'heart',\n", + " 'become',\n", + " 'a\\ntree',\n", + " 'heavy-laden',\n", + " 'with',\n", + " 'fruit',\n", + " 'that',\n", + " 'I',\n", + " 'may\\ngather',\n", + " 'and',\n", + " 'give',\n", + " 'unto',\n", + " 'them?\\n\\nAnd',\n", + " 'shall',\n", + " 'my',\n", + " 'desires',\n", + " 'flow',\n", + " 'like',\n", + " 'a\\nfountain',\n", + " 'that',\n", + " 'I',\n", + " 'may',\n", + " 'fill',\n", + " 'their',\n", + " 'cups?\\n\\nAm',\n", + " 'I',\n", + " 'a',\n", + " 'harp',\n", + " 'that',\n", + " 'the',\n", + " 'hand',\n", + " 'of',\n", + " 'the',\n", + " 'mighty\\nmay',\n", + " 'touch',\n", + " 'me,',\n", + " 'or',\n", + " 'a',\n", + " 'flute',\n", + " 'that',\n", + " 'his',\n", + " 'breath\\nmay',\n", + " 'pass',\n", + " 'through',\n", + " 'me?\\n\\nA',\n", + " 'seeker',\n", + " 'of',\n", + " 'silences',\n", + " 'am',\n", + " 'I,',\n", + " 'and',\n", + " 'what\\ntreasure',\n", + " 'have',\n", + " 'I',\n", + " 'found',\n", + " 'in',\n", + " 'silences',\n", + " 'that',\n", + " 'I\\nmay',\n", + " 'dispense',\n", + " 'with',\n", + " 'confidence?\\n\\nIf',\n", + " 'this',\n", + " 'is',\n", + " 'my',\n", + " 'day',\n", + " 'of',\n", + " 'harvest,',\n", + " 'in',\n", + " 'what\\nfields',\n", + " 'have',\n", + " 'I',\n", + " 'sowed',\n", + " 'the',\n", + " 'seed,',\n", + " 'and',\n", + " 'in\\nwhat',\n", + " 'unremembered',\n", + " 'seasons?\\n\\nIf',\n", + " 'this',\n", + " 'indeed',\n", + " 'be',\n", + " 'the',\n", + " 'hour',\n", + " 'in',\n", + " 'which',\n", + " 'I\\nlift',\n", + " 'up',\n", + " 'my',\n", + " 'lantern,',\n", + " 'it',\n", + " 'is',\n", + " 'not',\n", + " 'my',\n", + " 'flame\\nthat',\n", + " 'shall',\n", + " 'burn',\n", + " 'therein.\\n\\nEmpty',\n", + " 'and',\n", + " 'dark',\n", + " 'shall',\n", + " 'I',\n", + " 'raise',\n", + " 'my',\n", + " 'lantern,\\n\\nAnd',\n", + " 'the',\n", + " 'guardian',\n", + " 'of',\n", + " 'the',\n", + " 'night',\n", + " 'shall',\n", + " 'fill\\nit',\n", + " 'with',\n", + " 'oil',\n", + " 'and',\n", + " 'he',\n", + " 'shall',\n", + " 'light',\n", + " 'it',\n", + " 'also.\\n\\n*****\\n\\nThese',\n", + " 'things',\n", + " 'he',\n", + " 'said',\n", + " 'in',\n", + " 'words.',\n", + " 'But',\n", + " 'much\\nin',\n", + " 'his',\n", + " 'heart',\n", + " 'remained',\n", + " 'unsaid.',\n", + " 'For',\n", + " '{12}he\\nhimself',\n", + " 'could',\n", + " 'not',\n", + " 'speak',\n", + " 'his',\n", + " 'deeper\\nsecret.\\n\\n*****\\n\\n[Illustration:',\n", + " '0020]\\n\\nAnd',\n", + " 'when',\n", + " 'he',\n", + " 'entered',\n", + " 'into',\n", + " 'the',\n", + " 'city',\n", + " 'all\\nthe',\n", + " 'people',\n", + " 'came',\n", + " 'to',\n", + " 'meet',\n", + " 'him,',\n", + " 'and',\n", + " 'they\\nwere',\n", + " 'crying',\n", + " 'out',\n", + " 'to',\n", + " 'him',\n", + " 'as',\n", + " 'with',\n", + " 'one\\nvoice.\\n\\nAnd',\n", + " 'the',\n", + " 'elders',\n", + " 'of',\n", + " 'the',\n", + " 'city',\n", + " 'stood',\n", + " 'forth\\nand',\n", + " 'said:\\n\\nGo',\n", + " 'not',\n", + " 'yet',\n", + " 'away',\n", + " 'from',\n", + " 'us.\\n\\nA',\n", + " 'noontide',\n", + " 'have',\n", + " 'you',\n", + " 'been',\n", + " 'in',\n", + " 'our\\ntwilight,',\n", + " 'and',\n", + " 'your',\n", + " 'youth',\n", + " 'has',\n", + " 'given',\n", + " 'us\\ndreams',\n", + " 'to',\n", + " 'dream.\\n\\nNo',\n", + " 'stranger',\n", + " 'are',\n", + " 'you',\n", + " 'among',\n", + " 'us,',\n", + " 'nor\\na',\n", + " 'guest,',\n", + " 'but',\n", + " 'our',\n", + " 'son',\n", + " 'and',\n", + " 'our',\n", + " 'dearly\\nbeloved.\\n\\nSuffer',\n", + " 'not',\n", + " 'yet',\n", + " 'our',\n", + " 'eyes',\n", + " 'to',\n", + " 'hunger',\n", + " 'for\\nyour',\n", + " 'face.\\n\\n*****\\n\\nAnd',\n", + " 'the',\n", + " 'priests',\n", + " 'and',\n", + " 'the',\n", + " 'priestesses',\n", + " 'said\\nunto',\n", + " 'him:\\n\\nLet',\n", + " 'not',\n", + " 'the',\n", + " 'waves',\n", + " 'of',\n", + " 'the',\n", + " 'sea',\n", + " 'separate',\n", + " 'us\\nnow,',\n", + " 'and',\n", + " 'the',\n", + " 'years',\n", + " 'you',\n", + " 'have',\n", + " 'spent',\n", + " 'in',\n", + " 'our\\nmidst',\n", + " 'become',\n", + " 'a',\n", + " 'memory.\\n\\nYou',\n", + " 'have',\n", + " 'walked',\n", + " 'among',\n", + " 'us',\n", + " 'a',\n", + " 'spirit,\\n{13}and',\n", + " 'your',\n", + " 'shadow',\n", + " 'has',\n", + " 'been',\n", + " 'a',\n", + " 'light\\nupon',\n", + " 'our',\n", + " 'faces.\\n\\nMuch',\n", + " 'have',\n", + " 'we',\n", + " 'loved',\n", + " 'you.',\n", + " 'But',\n", + " 'speechless\\nwas',\n", + " 'our',\n", + " 'love,',\n", + " 'and',\n", + " 'with',\n", + " 'veils',\n", + " 'has',\n", + " 'it',\n", + " 'been\\nveiled.\\n\\nYet',\n", + " 'now',\n", + " 'it',\n", + " 'cries',\n", + " 'aloud',\n", + " 'unto',\n", + " 'you,',\n", + " 'and\\nwould',\n", + " 'stand',\n", + " 'revealed',\n", + " 'before',\n", + " 'you.\\n\\nAnd',\n", + " 'ever',\n", + " 'has',\n", + " 'it',\n", + " 'been',\n", + " 'that',\n", + " 'love',\n", + " 'knows\\nnot',\n", + " 'its',\n", + " 'own',\n", + " 'depth',\n", + " 'until',\n", + " 'the',\n", + " 'hour',\n", + " 'of\\nseparation.\\n\\n*****\\n\\nAnd',\n", + " 'others',\n", + " 'came',\n", + " 'also',\n", + " 'and',\n", + " 'entreated',\n", + " 'him.\\nBut',\n", + " 'he',\n", + " 'answered',\n", + " 'them',\n", + " 'not.',\n", + " 'He',\n", + " 'only',\n", + " 'bent\\nhis',\n", + " 'head;',\n", + " 'and',\n", + " 'those',\n", + " 'who',\n", + " 'stood',\n", + " 'near',\n", + " 'saw\\nhis',\n", + " 'tears',\n", + " 'falling',\n", + " 'upon',\n", + " 'his',\n", + " 'breast.\\n\\nAnd',\n", + " 'he',\n", + " 'and',\n", + " 'the',\n", + " 'people',\n", + " 'proceeded',\n", + " 'towards\\nthe',\n", + " 'great',\n", + " 'square',\n", + " 'before',\n", + " 'the',\n", + " 'temple.\\n\\nAnd',\n", + " 'there',\n", + " 'came',\n", + " 'out',\n", + " 'of',\n", + " 'the',\n", + " 'sanctuary',\n", + " 'a\\nwoman',\n", + " 'whose',\n", + " 'name',\n", + " 'was',\n", + " 'Almitra.',\n", + " 'And',\n", + " 'she\\nwas',\n", + " 'a',\n", + " 'seeress.\\n\\nAnd',\n", + " 'he',\n", + " 'looked',\n", + " 'upon',\n", + " 'her',\n", + " 'with',\n", + " 'exceeding\\ntenderness,',\n", + " 'for',\n", + " 'it',\n", + " 'was',\n", + " 'she',\n", + " 'who',\n", + " 'had',\n", + " 'first\\nsought',\n", + " 'and',\n", + " 'believed',\n", + " 'in',\n", + " 'him',\n", + " 'when',\n", + " 'he',\n", + " 'had\\nbeen',\n", + " 'but',\n", + " 'a',\n", + " 'day',\n", + " 'in',\n", + " 'their',\n", + " 'city.',\n", + " '{14}And\\nshe',\n", + " 'hailed',\n", + " 'him,',\n", + " 'saying:\\n\\nProphet',\n", + " 'of',\n", + " 'God,',\n", + " 'in',\n", + " 'quest',\n", + " 'of',\n", + " 'the\\nuttermost,',\n", + " 'long',\n", + " 'have',\n", + " 'you',\n", + " 'searched',\n", + " 'the\\ndistances',\n", + " 'for',\n", + " 'your',\n", + " 'ship.\\n\\nAnd',\n", + " 'now',\n", + " 'your',\n", + " 'ship',\n", + " 'has',\n", + " 'come,',\n", + " 'and',\n", + " 'you',\n", + " 'must\\nneeds',\n", + " 'go.\\n\\nDeep',\n", + " 'is',\n", + " 'your',\n", + " 'longing',\n", + " 'for',\n", + " 'the',\n", + " 'land',\n", + " 'of\\nyour',\n", + " 'memories',\n", + " 'and',\n", + " 'the',\n", + " 'dwelling',\n", + " 'place\\nof',\n", + " 'your',\n", + " 'greater',\n", + " 'desires;',\n", + " 'and',\n", + " 'our',\n", + " 'love\\nwould',\n", + " 'not',\n", + " 'bind',\n", + " 'you',\n", + " 'nor',\n", + " 'our',\n", + " 'needs',\n", + " 'hold\\nyou.\\n\\nYet',\n", + " 'this',\n", + " 'we',\n", + " 'ask',\n", + " 'ere',\n", + " 'you',\n", + " 'leave',\n", + " 'us,',\n", + " 'that\\nyou',\n", + " 'speak',\n", + " 'to',\n", + " 'us',\n", + " 'and',\n", + " 'give',\n", + " 'us',\n", + " 'of',\n", + " 'your\\ntruth.\\n\\nAnd',\n", + " 'we',\n", + " 'will',\n", + " 'give',\n", + " 'it',\n", + " 'unto',\n", + " 'our',\n", + " 'children,\\nand',\n", + " 'they',\n", + " 'unto',\n", + " 'their',\n", + " 'children,',\n", + " 'and',\n", + " 'it\\nshall',\n", + " 'not',\n", + " 'perish.\\n\\nIn',\n", + " 'your',\n", + " 'aloneness',\n", + " 'you',\n", + " 'have',\n", + " 'watched',\n", + " 'with\\nour',\n", + " 'days,',\n", + " 'and',\n", + " 'in',\n", + " 'your',\n", + " 'wakefulness',\n", + " 'you\\nhave',\n", + " 'listened',\n", + " 'to',\n", + " 'the',\n", + " 'weeping',\n", + " 'and',\n", + " 'the\\nlaughter',\n", + " 'of',\n", + " 'our',\n", + " 'sleep.\\n\\nNow',\n", + " 'therefore',\n", + " 'disclose',\n", + " 'us',\n", + " 'to',\n", + " 'ourselves,\\nand',\n", + " 'tell',\n", + " 'us',\n", + " 'all',\n", + " 'that',\n", + " 'has',\n", + " 'been',\n", + " 'shown\\nyou',\n", + " 'of',\n", + " 'that',\n", + " 'which',\n", + " 'is',\n", + " 'between',\n", + " 'birth',\n", + " 'and\\ndeath.\\n\\n*****\\n\\nAnd',\n", + " 'he',\n", + " 'answered,\\n\\nPeople',\n", + " 'of',\n", + " 'Orphalese,',\n", + " ...]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "prophet" ] }, { @@ -88,21 +1175,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 83, "metadata": {}, "outputs": [], "source": [ + "\n", "def reference(x):\n", - " '''\n", - " Input: A string\n", - " Output: The string with references removed\n", + " return re.split('{[0-9]+}', x)[0]\n", + "\n", + "\n", + " #'''\n", + " #Input: A string\n", + " #Output: The string with references removed\n", " \n", - " Example:\n", - " Input: 'the{7}'\n", - " Output: 'the'\n", - " '''\n", + " #Example:\n", + " #Input: 'the{7}'\n", + " #Output: 'the'\n", + " #'''\n", " \n", - " # your code here" + " # your code here\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['the', '7}']" + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#prophet[1].split(\"{\")" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [], + "source": [ + "#def remove(character):\n", + "# return string.split(\"{\", \"\")\n", + " " ] }, { @@ -114,11 +1237,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "import re" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['PROPHET\\n\\n|Almustafa,',\n", + " 'the',\n", + " 'chosen',\n", + " 'and',\n", + " 'the\\nbeloved,',\n", + " 'who',\n", + " 'was',\n", + " 'a',\n", + " 'dawn',\n", + " 'unto']" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# your code here\n", + "\n", + "prophet_reference = list(map(reference, prophet))\n", + "prophet_reference[0:10]" ] }, { @@ -130,7 +1285,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 91, "metadata": {}, "outputs": [], "source": [ @@ -143,7 +1298,7 @@ " Input: 'the\\nbeloved'\n", " Output: ['the', 'beloved']\n", " '''\n", - " \n", + " return re.split('\\n', x)[0]\n", " # your code here" ] }, @@ -156,11 +1311,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 92, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "prophet_line = list(map(line_break, prophet_reference))" ] }, { @@ -172,11 +1328,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 93, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['PROPHET', 'the', 'chosen', 'and', 'the', 'who', 'was', 'a', 'dawn', 'unto']" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "\n", + "prophet_flat = prophet_line\n", + "prophet_flat[0:10]" ] }, { @@ -190,7 +1360,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 95, "metadata": {}, "outputs": [], "source": [ @@ -210,6 +1380,10 @@ " '''\n", " \n", " word_list = ['and', 'the', 'a', 'an']\n", + " if x in word_list:\n", + " return False\n", + " else:\n", + " return True\n", " \n", " # your code here" ] @@ -221,6 +1395,15 @@ "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": 96, + "metadata": {}, + "outputs": [], + "source": [ + "prophet_filter = list(filter(word_filter, prophet_flat))" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -232,13 +1415,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 98, "metadata": {}, "outputs": [], "source": [ "def word_filter_case(x):\n", " \n", " word_list = ['and', 'the', 'a', 'an']\n", + " if x.lower in word_list:\n", + " return False\n", + " else:\n", + " return True\n", " \n", " # your code here" ] @@ -256,7 +1443,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 99, "metadata": {}, "outputs": [], "source": [ @@ -269,7 +1456,7 @@ " Input: 'John', 'Smith'\n", " Output: 'John Smith'\n", " '''\n", - " \n", + " return a + ' ' + b\n", " # your code here" ] }, @@ -282,11 +1469,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 100, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "prophet_filter = reduce(concat_space, prophet_filter)" ] }, { @@ -302,11 +1490,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 104, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "#df = pd.read_csv(\"Users/luisdemiguel/Downloads/PRSA_data_2010.1.1-2014.12.31.csv\")" ] }, { @@ -318,11 +1507,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 105, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here \n", + "# I cant find the csb\n", + "#df.head()" ] }, { @@ -334,21 +1525,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 106, "metadata": {}, "outputs": [], "source": [ - "def hourly(x):\n", - " '''\n", - " Input: A numerical value\n", - " Output: The value divided by 24\n", + "#def hourly(x):\n", + " #'''\n", + " #Input: A numerical value\n", + " #Output: The value divided by 24\n", " \n", - " Example:\n", - " Input: 48\n", - " Output: 2.0\n", - " '''\n", + " #Example:\n", + " #Input: 48\n", + " #Output: 2.0\n", + " #'''\n", " \n", - " # your code here" + " # your code here\n", + " #return x / 24" ] }, { @@ -360,11 +1552,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 107, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "\n", + "#m25_hourly = df[['Iws', 'Is', 'Ir']]\n", + "#pm25_hourly.apply(hourly)" ] }, { @@ -378,29 +1573,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 108, "metadata": {}, "outputs": [], "source": [ - "def sample_sd(x):\n", - " '''\n", - " Input: A Pandas series of values\n", - " Output: the standard deviation divided by the number of elements in the series\n", + "#def sample_sd(x):\n", + " #'''\n", + " #Input: A Pandas series of values\n", + " #Output: the standard deviation divided by the number of elements in the series\n", " \n", - " Example:\n", - " Input: pd.Series([1,2,3,4])\n", - " Output: 0.3726779962\n", - " '''\n", - " \n", + " #Example:\n", + " #Input: pd.Series([1,2,3,4])\n", + " #Output: 0.3726779962\n", + " #'''\n", + " #return np.std(x) / x.count() -1\n", " # your code here" ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": {}, + "outputs": [], + "source": [ + "#cols.apply(sample_sd)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [conda env:ihm1_env]", "language": "python", - "name": "python3" + "name": "conda-env-ihm1_env-py" }, "language_info": { "codemirror_mode": { @@ -412,7 +1623,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.3" } }, "nbformat": 4,