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: 141 additions & 48 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -48,9 +48,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"13637"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(prophet)"
]
Expand All @@ -66,11 +77,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"prophet = prophet[568:]"
]
},
{
Expand All @@ -82,11 +93,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"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"
"print(prophet[0:10])"
]
},
{
Expand All @@ -100,7 +119,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -114,16 +133,25 @@
" Output: 'the'\n",
" '''\n",
" \n",
" # your code here"
" organised_prophet = []\n",
" # your code here\n",
" for i in x.split(): #Splits the text x into a list of words using whitespace\n",
" if \"{\" not in i: #If the word does not contain a { character ( i.e., a normal word like \"the\" or \"prophet\"):\n",
" organised_prophet.append(i) #Just append it as-is to list organise_prophet\n",
" else:\n",
" index = i.find('{') #It finds the index(POSITION) of thc character '{' in x\n",
" organised_prophet.append(i[:index]) #This adds only the part before '{'\n",
" return \" \".join(organised_prophet)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"prophet_reference = list(map(reference, prophet))"
]
},
{
Expand All @@ -135,11 +163,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['PROPHET |Almustafa,', 'the', 'chosen', 'and', 'the beloved,', 'who', 'was', 'a', 'dawn', 'unto', 'his', 'own day,', 'had', 'waited', 'twelve', 'years', 'in', 'the', 'city of', 'Orphalese']\n"
]
}
],
"source": [
"prophet_reference = list(map(reference, prophet))\n",
"\n",
"print(prophet_reference[:20])"
]
},
{
Expand All @@ -151,11 +189,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"def line_break(x):\n",
" return x.split('\\n')\n",
" '''\n",
" Input: A string\n",
" Output: A list of strings split on the line break (\\n) character\n",
Expand All @@ -165,7 +204,7 @@
" Output: ['the', 'beloved']\n",
" '''\n",
" \n",
" # your code here"
" "
]
},
{
Expand All @@ -181,9 +220,19 @@
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# your code here"
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<map object at 0x000001EA8084E230>\n"
]
}
],
"source": [
"prophet_line = map(line_break, prophet_reference)\n",
"\n",
"\n"
]
},
{
Expand All @@ -195,22 +244,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
"prophet_flat = [i for sub in prophet_line for i in sub]\n",
"prophet_flat"
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['PROPHET |Almustafa,', 'the', 'chosen', 'and', 'the beloved,', 'who', 'was', 'a', 'dawn', 'unto', 'his', 'own day,', 'had', 'waited', 'twelve', 'years', 'in', 'the', 'city of', 'Orphalese']\n"
]
}
],
"source": [
"# To flatten the prophet_reference (list of lists) into a single list\n",
"prophet_flat = [word for sublist in prophet_line for word in sublist]\n",
"\n",
"\n",
"print(prophet_flat[:20])\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
]
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"PROPHET |Almustafa,the\n"
]
}
],
"source": []
},
{
"cell_type": "markdown",
Expand All @@ -223,7 +290,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 58,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -244,7 +311,7 @@
" \n",
" word_list = ['and', 'the', 'a', 'an']\n",
" \n",
" # your code here"
" "
]
},
{
Expand All @@ -256,13 +323,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 67,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# your code here"
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['PROPHET |Almustafa,', 'chosen', 'the beloved,', 'who', 'was', 'dawn', 'unto', 'his', 'own day,', 'had', 'waited', 'twelve', 'years', 'in', 'city of', 'Orphalese']\n"
]
}
],
"source": [
"word_list = ['and', 'the', 'a', 'an']\n",
"\n",
"def word_filter(x):\n",
" return x not in word_list \n",
"\n",
"prophet_filter = list(filter(word_filter, prophet_flat[:20]))\n",
"print(prophet_filter)"
]
},
{
Expand All @@ -276,15 +357,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 68,
"metadata": {},
"outputs": [],
"source": [
"def word_filter_case(x):\n",
" return x not in word_list\n",
" \n",
" word_list = ['and', 'the', 'a', 'an']\n",
" \n",
" # your code here"
" "
]
},
{
Expand All @@ -300,7 +382,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 72,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -314,7 +396,8 @@
" Output: 'John Smith'\n",
" '''\n",
" \n",
" # your code here"
" return a + ' ' + b\n",
"\n"
]
},
{
Expand All @@ -324,9 +407,7 @@
"scrolled": true
},
"outputs": [],
"source": [
"# your code here"
]
"source": []
},
{
"cell_type": "markdown",
Expand All @@ -337,17 +418,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 77,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"PROPHET |Almustafa, chosen the beloved, who was dawn unto his own day, had waited twelve years in city of Orphalese\n"
]
}
],
"source": [
"# your code here"
"from functools import reduce\n",
"\n",
"prophet_string = reduce(concat_space, prophet_filter)\n",
"\n",
"print(prophet_string)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -361,7 +454,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down