Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 152 additions & 37 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 60,
"metadata": {},
"outputs": [],
"source": [
"# Run this code:\n",
"\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"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -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]"
]
},
{
Expand All @@ -88,7 +113,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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"
]
},
{
Expand All @@ -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])"
]
},
{
Expand All @@ -130,7 +172,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 65,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -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])"
]
},
{
Expand All @@ -190,7 +251,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 68,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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"
]
},
{
Expand All @@ -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": {},
Expand All @@ -232,15 +314,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 70,
"metadata": {},
"outputs": [],
"source": [
"def word_filter_case(x):\n",
" \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])"
]
},
{
Expand All @@ -256,7 +359,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 73,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -270,7 +373,9 @@
" Output: 'John Smith'\n",
" '''\n",
" \n",
" # your code here"
" # your code here\n",
" \n",
" return a + \" \" + b"
]
},
{
Expand All @@ -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"
]
},
{
Expand Down Expand Up @@ -412,7 +527,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.7.6"
}
},
"nbformat": 4,
Expand Down