From cdd5c051195cbdc6c68627ddee24c240e5af6db3 Mon Sep 17 00:00:00 2001 From: jthorne2000 Date: Mon, 3 Feb 2025 14:19:11 +0000 Subject: [PATCH] finished 3-8 homework --- lists.ipynb | 298 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 232 insertions(+), 66 deletions(-) diff --git a/lists.ipynb b/lists.ipynb index 38de076..cd578c6 100644 --- a/lists.ipynb +++ b/lists.ipynb @@ -97,7 +97,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -106,7 +106,7 @@ "'Alcman'" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -124,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -133,7 +133,7 @@ "str" ] }, - "execution_count": 6, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -151,7 +151,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -160,7 +160,7 @@ "'alcman'" ] }, - "execution_count": 7, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -171,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -180,7 +180,7 @@ "'ALCMAN'" ] }, - "execution_count": 8, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -198,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -207,7 +207,7 @@ "'Pindar'" ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -225,7 +225,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -234,7 +234,7 @@ "'Pindar'" ] }, - "execution_count": 10, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -252,7 +252,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -261,7 +261,7 @@ "'Pindar'" ] }, - "execution_count": 11, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -279,7 +279,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -288,7 +288,7 @@ "'Bacchylides'" ] }, - "execution_count": 12, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -306,7 +306,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -315,7 +315,7 @@ "'Alcman'" ] }, - "execution_count": 13, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -326,7 +326,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -335,7 +335,7 @@ "'Stesichorus'" ] }, - "execution_count": 14, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -346,7 +346,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -355,7 +355,7 @@ "'Stesichorus'" ] }, - "execution_count": 15, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -375,7 +375,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -392,7 +392,7 @@ " 'Pindar']" ] }, - "execution_count": 16, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -411,7 +411,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -420,7 +420,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -438,7 +438,7 @@ " 'Horace']" ] }, - "execution_count": 18, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -449,7 +449,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -463,7 +463,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -481,7 +481,7 @@ " 'Horace']" ] }, - "execution_count": 22, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -499,7 +499,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -518,7 +518,7 @@ " 'Horace']" ] }, - "execution_count": 23, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -537,7 +537,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -557,7 +557,7 @@ " 'Homer']" ] }, - "execution_count": 24, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -576,7 +576,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -585,7 +585,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -604,7 +604,7 @@ " 'Horace']" ] }, - "execution_count": 26, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -626,7 +626,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -663,7 +663,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -672,7 +672,7 @@ "['F2018', 'S2019', 'F2019', 'S2020', 'F2021']" ] }, - "execution_count": 28, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -683,7 +683,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -692,7 +692,7 @@ "'F2021'" ] }, - "execution_count": 29, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -703,7 +703,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -712,7 +712,7 @@ "['F2018', 'S2019', 'F2019', 'S2020']" ] }, - "execution_count": 30, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -730,7 +730,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ @@ -739,7 +739,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -748,7 +748,7 @@ "['F2018', 'S2019', 'F2019']" ] }, - "execution_count": 32, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -775,7 +775,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -784,7 +784,7 @@ "[3, 4, 1, 5, -1, 8]" ] }, - "execution_count": 33, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -796,7 +796,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -805,7 +805,7 @@ "[-1, 1, 3, 4, 5, 8]" ] }, - "execution_count": 34, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -824,7 +824,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -833,7 +833,7 @@ "[3, 4, 1, 5, -1, 8]" ] }, - "execution_count": 35, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -845,14 +845,14 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[8, 5, 4, 3, 1, -1]\n", + "[-1, 1, 3, 4, 5, 8]\n", "[3, 4, 1, 5, -1, 8]\n" ] } @@ -873,16 +873,16 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[8, -1, 5, 1, 4, 3]" + "[3, 4, 1, 5, -1, 8]" ] }, - "execution_count": 38, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -908,7 +908,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -917,7 +917,7 @@ "6" ] }, - "execution_count": 39, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -937,7 +937,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -947,7 +947,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[41], 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", + "Cell \u001b[0;32mIn[37], 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" ] } @@ -965,16 +965,16 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "3" + "8" ] }, - "execution_count": 44, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -985,7 +985,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -1019,6 +1019,172 @@ "\n", "Complete Exercise 3-8 in Matthes (2023, p. 45)." ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [], + "source": [ + "places_list = [\"Athens\", \"Rome\", \"Buenos Aires\", \"Dublin\",\"Frankfurt\", \"Bucharest\", \"Amsterdam\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Athens', 'Rome', 'Buenos Aires', 'Dublin', 'Frankfurt', 'Bucharest', 'Amsterdam']\n" + ] + } + ], + "source": [ + "print(places_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Amsterdam', 'Athens', 'Bucharest', 'Buenos Aires', 'Dublin', 'Frankfurt', 'Rome']\n" + ] + } + ], + "source": [ + "print(sorted(places_list))" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Athens', 'Rome', 'Buenos Aires', 'Dublin', 'Frankfurt', 'Bucharest', 'Amsterdam']\n" + ] + } + ], + "source": [ + "print(places_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Rome', 'Frankfurt', 'Dublin', 'Buenos Aires', 'Bucharest', 'Athens', 'Amsterdam']\n" + ] + } + ], + "source": [ + "print(sorted(places_list, reverse=True))" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Athens', 'Rome', 'Buenos Aires', 'Dublin', 'Frankfurt', 'Bucharest', 'Amsterdam']\n" + ] + } + ], + "source": [ + "print(places_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Amsterdam', 'Bucharest', 'Frankfurt', 'Dublin', 'Buenos Aires', 'Rome', 'Athens']\n" + ] + } + ], + "source": [ + "places_list.reverse()\n", + "print(places_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Athens', 'Rome', 'Buenos Aires', 'Dublin', 'Frankfurt', 'Bucharest', 'Amsterdam']\n" + ] + } + ], + "source": [ + "places_list.reverse()\n", + "print(places_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Amsterdam', 'Athens', 'Bucharest', 'Buenos Aires', 'Dublin', 'Frankfurt', 'Rome']\n" + ] + } + ], + "source": [ + "places_list.sort()\n", + "print(places_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Rome', 'Frankfurt', 'Dublin', 'Buenos Aires', 'Bucharest', 'Athens', 'Amsterdam']\n" + ] + } + ], + "source": [ + "places_list.sort(reverse=True)\n", + "print(places_list)" + ] } ], "metadata": {