From 7e1ef7a8800697120539eceb7ca1bfee57367173 Mon Sep 17 00:00:00 2001 From: bbobb <124208046+bbobb@users.noreply.github.com> Date: Mon, 3 Feb 2025 00:18:43 +0000 Subject: [PATCH] git commit -am "lists exercises" --- lists.ipynb | 491 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 418 insertions(+), 73 deletions(-) diff --git a/lists.ipynb b/lists.ipynb index 28ed228..93c29e5 100644 --- a/lists.ipynb +++ b/lists.ipynb @@ -36,9 +36,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Alcman', 'Sappho', 'Alcaeus', 'Anacreon', 'Stesichorus', 'Ibycus', 'Simonides', 'Bacchylides', 'Pindar']\n" + ] + } + ], "source": [ "print(lyric_poets)" ] @@ -52,9 +60,28 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Alcman',\n", + " 'Sappho',\n", + " 'Alcaeus',\n", + " 'Anacreon',\n", + " 'Stesichorus',\n", + " 'Ibycus',\n", + " 'Simonides',\n", + " 'Bacchylides',\n", + " 'Pindar']" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets" ] @@ -70,9 +97,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Alcman'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[0]" ] @@ -86,9 +124,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(lyric_poets[0])" ] @@ -102,18 +151,40 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'alcman'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[0].lower()" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'ALCMAN'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[0].upper()" ] @@ -127,9 +198,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Pindar'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[8]" ] @@ -143,9 +225,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Pindar'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[len(lyric_poets) - 1]" ] @@ -159,9 +252,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Pindar'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[-1]" ] @@ -175,9 +279,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Bacchylides'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[-2]" ] @@ -200,9 +315,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['Alkman',\n", + " 'Sappho',\n", + " 'Alcaeus',\n", + " 'Anacreon',\n", + " 'Stesichorus',\n", + " 'Ibycus',\n", + " 'Simonides',\n", + " 'Bacchylides',\n", + " 'Pindar']" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[0] = 'Alkman'\n", "lyric_poets" @@ -217,7 +351,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -226,9 +360,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Alkman',\n", + " 'Sappho',\n", + " 'Alcaeus',\n", + " 'Anacreon',\n", + " 'Stesichorus',\n", + " 'Ibycus',\n", + " 'Simonides',\n", + " 'Bacchylides',\n", + " 'Pindar',\n", + " 'Horace']" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets" ] @@ -242,9 +396,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['Alkman',\n", + " 'Sappho',\n", + " 'Alcaeus',\n", + " 'Anacreon',\n", + " 'Ovid',\n", + " 'Stesichorus',\n", + " 'Ibycus',\n", + " 'Simonides',\n", + " 'Bacchylides',\n", + " 'Pindar',\n", + " 'Horace']" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets.insert(4, \"Ovid\")\n", "lyric_poets" @@ -259,9 +434,31 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['Alkman',\n", + " 'Sappho',\n", + " 'Alcaeus',\n", + " 'Anacreon',\n", + " 'Ovid',\n", + " 'Stesichorus',\n", + " 'Ibycus',\n", + " 'Simonides',\n", + " 'Bacchylides',\n", + " 'Pindar',\n", + " 'Horace',\n", + " 'Homer']" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets.append(\"Homer\")\n", "lyric_poets" @@ -276,7 +473,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -296,9 +493,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I most recently taught in S2022.\n", + "I also taught in F2018, S2019, F2019, S2020, F2021.\n" + ] + } + ], "source": [ "teaching_semesters = [\"F2018\", \"S2019\", \"F2019\", \"S2020\", \"F2021\", \"S2022\"]\n", "\n", @@ -324,9 +530,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['F2018', 'S2019', 'F2019', 'F2021']" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "teaching_semesters" ] @@ -340,9 +557,21 @@ }, { "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [], + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "list.remove(x): x not in list", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[25], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mteaching_semesters\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mremove\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mS2020\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# partially online due to Covid\u001b[39;00m\n", + "\u001b[0;31mValueError\u001b[0m: list.remove(x): x not in list" + ] + } + ], "source": [ "teaching_semesters.remove(\"S2020\") # partially online due to Covid" ] @@ -374,9 +603,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 4, 1, 5, -1, 8]" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_list = [3, 4, 1, 5, -1, 8]\n", "my_list" @@ -384,9 +624,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[-1, 1, 3, 4, 5, 8]" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_list.sort()\n", "my_list" @@ -401,9 +652,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 4, 1, 5, -1, 8]" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_list = [3, 4, 1, 5, -1, 8]\n", "my_list" @@ -411,9 +673,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[-1, 1, 3, 4, 5, 8]\n", + "[3, 4, 1, 5, -1, 8]\n" + ] + } + ], "source": [ "print(sorted(my_list))\n", "print(my_list)" @@ -430,9 +701,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[8, -1, 5, 1, 4, 3]" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_list.reverse()\n", "my_list" @@ -472,9 +754,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "ename": "IndexError", + "evalue": "list index out of range", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[31], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mmy_list\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m6\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[0;31mIndexError\u001b[0m: list index out of range" + ] + } + ], "source": [ "my_list[6]" ] @@ -488,9 +782,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_list[5]" ] @@ -510,11 +815,51 @@ "\n", "Complete Exercise 3-8 in Matthes (2023, p. 45)." ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Naples', 'Rabat', 'Tunis', 'Berlin', 'Arusha']\n", + "['Arusha', 'Berlin', 'Naples', 'Rabat', 'Tunis']\n", + "['Naples', 'Rabat', 'Tunis', 'Berlin', 'Arusha']\n", + "['Tunis', 'Rabat', 'Naples', 'Berlin', 'Arusha']\n", + "['Naples', 'Rabat', 'Tunis', 'Berlin', 'Arusha']\n", + "['Arusha', 'Berlin', 'Tunis', 'Rabat', 'Naples']\n", + "['Naples', 'Rabat', 'Tunis', 'Berlin', 'Arusha']\n", + "['Arusha', 'Berlin', 'Naples', 'Rabat', 'Tunis']\n", + "['Tunis', 'Rabat', 'Naples', 'Berlin', 'Arusha']\n" + ] + } + ], + "source": [ + "potential_places = [\"Naples\", \"Rabat\", \"Tunis\", \"Berlin\", \"Arusha\"]\n", + "print(potential_places)\n", + "print(sorted(potential_places))\n", + "print(potential_places)\n", + "alphabetical_places = sorted(potential_places)\n", + "alphabetical_places.reverse()\n", + "print(alphabetical_places)\n", + "print(potential_places)\n", + "potential_places.reverse()\n", + "print(potential_places)\n", + "potential_places.reverse()\n", + "print(potential_places)\n", + "potential_places.sort()\n", + "print(potential_places)\n", + "potential_places.reverse()\n", + "print(potential_places)" + ] } ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -528,7 +873,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.7" + "version": "3.12.1" } }, "nbformat": 4,