From 1df54fd8621204ef53532d7a1a0f70fc76e797c8 Mon Sep 17 00:00:00 2001 From: Katydi Date: Wed, 23 Jul 2025 16:40:45 +0100 Subject: [PATCH] MAP --- your-code/main.ipynb | 145 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 117 insertions(+), 28 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 9f0e67b..4a5ba3e 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -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" ] }, { @@ -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" ] }, { @@ -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" ] }, { @@ -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" ] }, { @@ -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" ] }, { @@ -151,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ @@ -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" ] }, { @@ -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" ] }, { @@ -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" ] }, { @@ -347,7 +436,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -361,7 +450,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,