diff --git a/lists.ipynb b/lists.ipynb index 28ed228..92453bd 100644 --- a/lists.ipynb +++ b/lists.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -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": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Alcman',\n", + " 'Sappho',\n", + " 'Alcaeus',\n", + " 'Anacreon',\n", + " 'Stesichorus',\n", + " 'Ibycus',\n", + " 'Simonides',\n", + " 'Bacchylides',\n", + " 'Pindar']" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets" ] @@ -70,9 +97,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Alcman'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[0]" ] @@ -86,9 +124,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(lyric_poets[0])" ] @@ -102,18 +151,40 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'alcman'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[0].lower()" ] }, { "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].upper()" ] @@ -127,9 +198,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Pindar'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[8]" ] @@ -143,9 +225,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[len(lyric_poets) - 1]" ] @@ -159,9 +252,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[-1]" ] @@ -175,9 +279,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Bacchylides'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[-2]" ] @@ -198,14 +313,47 @@ "What if we decide to transliterate κ as `k` instead of `c`? We can change the names in the list that are affected:" ] }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Alkman',\n", + " 'Sappho',\n", + " 'Alcaeus',\n", + " 'Anacreon',\n", + " 'Stesichorus',\n", + " 'Ibycus',\n", + " 'Simonides',\n", + " 'Bacchylides',\n", + " 'Pindar']" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lyric_poets[0] = 'Alkman'\n", + "lyric_poets" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "lyric_poets[0] = 'Alkman'\n", - "lyric_poets" + "new_poets = []\n", + "for poet in lyric_poets:\n", + " if poet == \"Horace\":\n", + " new_poets.append(poet)\n", + " else\n", + " poet.replace(\"c\", \"k\")" ] }, { @@ -217,7 +365,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -226,9 +374,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "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": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets" ] @@ -296,9 +464,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "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 +501,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['F2018', 'S2019', 'F2019', 'S2020', 'F2021']" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "teaching_semesters" ] @@ -340,7 +528,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -349,9 +537,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['F2018', 'S2019', 'F2019', 'F2021']" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "teaching_semesters" ] @@ -374,9 +573,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 4, 1, 5, -1, 8]" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_list = [3, 4, 1, 5, -1, 8]\n", "my_list" @@ -384,9 +594,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[-1, 1, 3, 4, 5, 8]" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_list.sort()\n", "my_list" @@ -396,7 +617,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "If you need to keep the original order of the list, yo ucan use `sorted()` instead." + "If you need to keep the original order of the list, you can use `sorted()` instead." ] }, { @@ -510,11 +731,158 @@ "\n", "Complete Exercise 3-8 in Matthes (2023, p. 45)." ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Osaka', 'Shanghai', 'St Petersburg', 'Barcelona', 'Montreal']\n" + ] + } + ], + "source": [ + "places_to_visit = [\"Osaka\", \"Shanghai\", \"St Petersburg\", \"Barcelona\", \"Montreal\"]\n", + "print(places_to_visit)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Barcelona', 'Montreal', 'Osaka', 'Shanghai', 'St Petersburg']" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(places_to_visit)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Osaka', 'Shanghai', 'St Petersburg', 'Barcelona', 'Montreal']\n" + ] + } + ], + "source": [ + "print(places_to_visit)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['St Petersburg', 'Shanghai', 'Osaka', 'Montreal', 'Barcelona']" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(places_to_visit, reverse=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Montreal', 'Barcelona', 'St Petersburg', 'Shanghai', 'Osaka']\n" + ] + } + ], + "source": [ + "places_to_visit.reverse()\n", + "print(places_to_visit)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Osaka', 'Shanghai', 'St Petersburg', 'Barcelona', 'Montreal']\n" + ] + } + ], + "source": [ + "places_to_visit.reverse()\n", + "print(places_to_visit)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Barcelona', 'Montreal', 'Osaka', 'Shanghai', 'St Petersburg']\n" + ] + } + ], + "source": [ + "places_to_visit.sort()\n", + "print(places_to_visit)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['St Petersburg', 'Shanghai', 'Osaka', 'Montreal', 'Barcelona']\n" + ] + } + ], + "source": [ + "places_to_visit.sort(reverse=True)\n", + "print(places_to_visit)" + ] } ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -528,7 +896,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.7" + "version": "3.12.1" } }, "nbformat": 4,