Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab Map-Filter #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
91 changes: 72 additions & 19 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"# your code here\n",
"# Remove the first 568 words\n",
"prophet = prophet[568:]\n",
"\n",
"# Verify the result\n",
"print(\"First 10 words after removing the initial 568:\", prophet[:10])\n"
]
},
{
Expand All @@ -86,7 +92,9 @@
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"# your code here\n",
"print(\"First 10 words in the `prophet` list:\", prophet[:10])\n"
]
},
{
Expand All @@ -104,17 +112,17 @@
"metadata": {},
"outputs": [],
"source": [
"def reference(x):\n",
" '''\n",
" Input: A string\n",
" Output: The string with references removed\n",
" \n",
" Example:\n",
" Input: 'the{7}'\n",
" Output: 'the'\n",
" '''\n",
" \n",
" # your code here"
"\n",
" # your code here\n",
"def remove_references(word):\n",
"\n",
" return word.split('{')[0]\n",
"prophet = [remove_references(word) for word in prophet]\n",
"# Example usage\n",
"example_words = ['word1{ref1}', 'word2', 'example{ref2}', 'text']\n",
"cleaned_words = [remove_references(word) for word in example_words]\n",
"\n",
"print(\"Cleaned words:\", cleaned_words)\n"
]
},
{
Expand All @@ -139,7 +147,11 @@
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"# your code here\n",
"prophet_reference = list(map(remove_references, prophet))\n",
"\n",
"print(\"First 10 words in `prophet_reference`:\", prophet_reference[:10])\n"
]
},
{
Expand All @@ -165,7 +177,8 @@
" Output: ['the', 'beloved']\n",
" '''\n",
" \n",
" # your code here"
" # your code here\n",
" return word.split('\\n')"
]
},
{
Expand All @@ -183,7 +196,11 @@
},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"prophet_line = [split_line_break(word) for word in prophet_reference]\n",
"\n",
"\n",
"print(\"First 10 elements in `prophet_line`:\", prophet_line[:10])\n"
]
},
{
Expand Down Expand Up @@ -262,7 +279,20 @@
},
"outputs": [],
"source": [
"# your code here"
"\n",
"# your code here\n",
"# List of words to exclude\n",
"exclude_words = [\"the\", \"a\", \"an\", \"in\", \"on\", \"at\", \"and\", \"or\", \"but\", \"if\", \"is\", \"it\"]\n",
"\n",
"# Define the filter function\n",
"def filter_words(word):\n",
"\n",
" return word.lower() not in exclude_words\n",
"\n",
"# Example usage\n",
"example_words = [\"the\", \"sun\", \"is\", \"shining\", \"on\", \"a\", \"beautiful\", \"day\"]\n",
"filtered_words = [word for word in example_words if filter_words(word)]\n",
"print(\"Filtered words:\", filtered_words)\n"
]
},
{
Expand Down Expand Up @@ -325,7 +355,15 @@
},
"outputs": [],
"source": [
"# your code here"
"\n",
"# your code here\n",
"# Define the concatenation function\n",
"def concatenate_with_space(str1, str2):\n",
" return f\"{str1} {str2}\"\n",
"\n",
"# Example usage\n",
"result = concatenate_with_space(\"Hello\", \"World\")\n",
"print(\"Concatenated string:\", result)\n"
]
},
{
Expand All @@ -341,7 +379,22 @@
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"from functools import reduce\n",
"\n",
"# Define the concatenation function\n",
"def concatenate_with_space(str1, str2):\n",
"\n",
" return f\"{str1} {str2}\"\n",
"\n",
"# Example list `prophet_filter`\n",
"prophet_filter = [\"This\", \"is\", \"a\", \"cleaned\", \"version\", \"of\", \"the\", \"text\", \"corpus\"]\n",
"\n",
"# Use reduce to combine the list into a single string\n",
"prophet_string = reduce(concatenate_with_space, prophet_filter)\n",
"\n",
"# Display the result\n",
"print(\"Prophet string:\", prophet_string)\n"
]
}
],
Expand Down