Skip to content
Open

MAP #243

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
145 changes: 117 additions & 28 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -35,7 +35,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -50,9 +50,20 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"list"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(prophet)"
"len(prophet)\n"
]
},
{
Expand All @@ -68,9 +79,23 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"outputs": [
{
"data": {
"text/plain": [
"11933"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Remove first 568 words\n",
"prophet = prophet[568:] # remove 567 words\n",
"\n",
"\n"
]
},
{
Expand All @@ -84,9 +109,17 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['sheaves', 'of', 'corn', 'he', 'gathers', 'you', 'unto\\nhimself.\\n\\nhe', 'threshes', 'you', 'to']\n"
]
}
],
"source": [
"# your code here"
"print(prophet[0:10]) # words from 1 to 10 \n"
]
},
{
Expand All @@ -100,30 +133,57 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['sheaves', 'of', 'corn', 'he', 'gathers', 'you', 'unto\\nhimself.\\n\\nhe', 'threshes', 'you', 'to']\n"
]
}
],
"source": [
"def reference(x):\n",
" '''\n",
" Input: A string\n",
" Output: The string with references removed\n",
" \n",
"\n",
" Example:\n",
" Input: 'the{7}'\n",
" Output: 'the'\n",
" '''\n",
" \n",
" # your code here"
" return x.split('{')[0] # Keep only the part before '{'\n",
"\n",
"# Apply the function to each word using map\n",
"prophet = list(map(reference, prophet))\n",
"\n",
"# Check the first 10 words\n",
"print(prophet[0:10])\n",
"\n",
"\n",
"\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "IndentationError",
"evalue": "unexpected indent (3436207849.py, line 2)",
"output_type": "error",
"traceback": [
"\u001b[1;36m Cell \u001b[1;32mIn[23], line 2\u001b[1;36m\u001b[0m\n\u001b[1;33m return x.split('{')[0] # Keep only the part before '{'\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unexpected indent\n"
]
}
],
"source": [
"# your code here"
"\n"
]
},
{
Expand All @@ -135,11 +195,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['AND', 'THE', 'PROPHET', 'SAID']\n"
]
}
],
"source": [
"# your code here\n",
"# Assuming you already have a function, for example:\n",
"def my_function(word):\n",
" return word.upper() # or any transformation logic\n",
"\n",
"# And you have a list (e.g., words from the book)\n",
"book_words = [\"and\", \"the\", \"prophet\", \"said\"]\n",
"\n",
"# Apply map() and convert the result to a list\n",
"prophet_reference = list(map(my_function, book_words))\n",
"\n",
"print(prophet_reference)\n"
]
},
{
Expand All @@ -151,7 +230,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -165,7 +244,15 @@
" Output: ['the', 'beloved']\n",
" '''\n",
" \n",
" # your code here"
" # your code here\n",
"\n",
"def line_break(x):\n",
" \"\"\"\n",
" Input: A string\n",
" Output: A list of strings split on the line break (\\n) character\n",
" \"\"\"\n",
" return x.split('\\n')\n",
"\n"
]
},
{
Expand All @@ -177,13 +264,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 37,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"prophet_line = list(map(line_break, prophet_reference))\n"
]
},
{
Expand All @@ -205,11 +293,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"prophet_flat = [i for sub in prophet_line for i in sub]\n"
]
},
{
Expand Down Expand Up @@ -347,7 +436,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -361,7 +450,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down