diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 9f0e67b..307c6ba 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -48,9 +48,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "13637" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "len(prophet)" ] @@ -66,11 +77,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "prophet = prophet[568:len(prophet)]\n" ] }, { @@ -82,11 +94,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PROPHET\n", + "\n", + "|Almustafa,\n", + "the{7}\n", + "chosen\n", + "and\n", + "the\n", + "beloved,\n", + "who\n", + "was\n", + "a\n", + "dawn\n", + "unto\n", + "his\n" + ] + } + ], + "source": [ + "# your code here\n", + "for i in range(0,11):\n", + " print(prophet[i])" ] }, { @@ -100,7 +135,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -114,16 +149,29 @@ " Output: 'the'\n", " '''\n", " \n", - " # your code here" + " # your code here\n", + " return x.split('{')[0]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'the'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "reference('the{7}')" ] }, { @@ -135,11 +183,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "prophet_reference = map(reference, prophet)" ] }, { @@ -151,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -164,6 +213,7 @@ " Input: 'the\\nbeloved'\n", " Output: ['the', 'beloved']\n", " '''\n", + " return x.split('\\n')\n", " \n", " # your code here" ] @@ -177,13 +227,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "scrolled": true }, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "prophet_line = map(line_break, prophet_reference)" ] }, { @@ -195,21 +246,16 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "prophet_flat = [i for sub in prophet_line for i in sub]\n", - "prophet_flat" - ] - }, - { - "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "prophet_flat = [\n", + " el\n", + " for row in prophet_line\n", + " for el in row\n", + "]" ] }, { @@ -223,7 +269,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -244,7 +290,11 @@ " \n", " word_list = ['and', 'the', 'a', 'an']\n", " \n", - " # your code here" + " # your code here\n", + " if x not in word_list:\n", + " return True\n", + " else:\n", + " return False" ] }, { @@ -256,13 +306,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "scrolled": true }, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "prophet_filter = filter(word_filter, prophet_flat)" ] }, { @@ -276,15 +327,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "def word_filter_case(x):\n", - " \n", + " '''\n", + " Input: A string\n", + " Output: True if the word is not in the specified list \n", + " and False if the word is in the list.\n", + " \n", + " Example:\n", + " word list = ['And', 'the']\n", + " Input: 'and'\n", + " Output: False\n", + " \n", + " Input: 'John'\n", + " Output: True\n", + " '''\n", + " \n", " word_list = ['and', 'the', 'a', 'an']\n", + " x = x.lower()\n", " \n", - " # your code here" + " # your code here\n", + " if x not in word_list:\n", + " return True\n", + " else:\n", + " return False" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "prophet_flat_filter = filter(word_filter_case, prophet_flat)" ] }, { @@ -300,7 +378,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -314,18 +392,31 @@ " Output: 'John Smith'\n", " '''\n", " \n", - " # your code here" + " # your code here\n", + " return f\"{a} {b}\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'test 123'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "concat_space('test', '123')" ] }, { @@ -337,17 +428,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "from functools import reduce\n", + "\n", + "def concat_space(a, b):\n", + " '''\n", + " Input:Two strings\n", + " Output: A single string separated by a space\n", + " \n", + " Example:\n", + " Input: 'John', 'Smith'\n", + " Output: 'John Smith'\n", + " '''\n", + " return f\"{a} {b}\"\n", + "\n", + "prophet_string = reduce(concat_space, prophet_filter)" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -361,7 +466,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.7" } }, "nbformat": 4,