diff --git a/lists.ipynb b/lists.ipynb index 28ed228..14ccbb6 100644 --- a/lists.ipynb +++ b/lists.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -36,9 +36,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "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, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['Alcman',\n", + " 'Sappho',\n", + " 'Alcaeus',\n", + " 'Anacreon',\n", + " 'Stesichorus',\n", + " 'Ibycus',\n", + " 'Simonides',\n", + " 'Bacchylides',\n", + " 'Pindar']" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets" ] @@ -70,9 +97,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "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, + "execution_count": 5, "metadata": {}, - "outputs": [], + "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, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'alcman'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[0].lower()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "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, + "execution_count": 8, "metadata": {}, - "outputs": [], + "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, + "execution_count": 9, "metadata": {}, - "outputs": [], + "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, + "execution_count": 10, "metadata": {}, - "outputs": [], + "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, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Bacchylides'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets[-2]" ] @@ -200,9 +315,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "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": 12, + "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": 13, "metadata": {}, "outputs": [], "source": [ @@ -226,9 +360,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "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" ] @@ -242,9 +396,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "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": 15, + "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": 16, "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": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "lyric_poets.append(\"Homer\")\n", "lyric_poets" @@ -296,9 +493,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "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 +530,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['F2018', 'S2019', 'F2019', 'S2020', 'F2021']" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "teaching_semesters" ] @@ -340,7 +557,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -349,9 +566,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['F2018', 'S2019', 'F2019', 'F2021']" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "teaching_semesters" ] @@ -374,9 +602,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 4, 1, 5, -1, 8]" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_list = [3, 4, 1, 5, -1, 8]\n", "my_list" @@ -384,9 +623,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[-1, 1, 3, 4, 5, 8]" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_list.sort()\n", "my_list" @@ -510,11 +760,266 @@ "\n", "Complete Exercise 3-8 in Matthes (2023, p. 45)." ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Store the locations in a list. Make sure the list is not in alphabetical order.\n", + "- Print your list in its original order. Don’t worry about printing the list neatly,\n", + "just print it as a raw Python list" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Japan', 'Taiwan', 'California', 'France', 'Canada']" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "five_places = [\"Japan\", \"Taiwan\", \"California\", \"France\", \"Canada\"]\n", + "five_places" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Use sorted() to print your list in alphabetical order without modifying the\n", + "actual list." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['California', 'Canada', 'France', 'Japan', 'Taiwan']" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(five_places)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Show that your list is still in its original order by printing it." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Japan', 'Taiwan', 'California', 'France', 'Canada']" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "five_places" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Use sorted() to print your list in reverse alphabetical order without changing the order of the original list." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Taiwan', 'Japan', 'France', 'Canada', 'California']" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(five_places, reverse=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Show that your list is still in its original order by printing it again" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Japan', 'Taiwan', 'California', 'France', 'Canada']" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "five_places" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Use reverse() to change the order of your list. Print the list to show that its\n", + "order has changed." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Canada', 'France', 'California', 'Taiwan', 'Japan']" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "five_places.reverse()\n", + "five_places" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Use reverse() to change the order of your list again. Print the list to show\n", + "it’s back to its original order" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Japan', 'Taiwan', 'California', 'France', 'Canada']" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "five_places.reverse()\n", + "five_places" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Use sort() to change your list so it’s stored in alphabetical order. Print the\n", + "list to show that its order has been changed." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['California', 'Canada', 'France', 'Japan', 'Taiwan']" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "five_places.sort()\n", + "five_places" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Use sort() to change your list so it’s stored in reverse alphabetical order.\n", + "Print the list to show that its order has changed." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Taiwan', 'Japan', 'France', 'Canada', 'California']" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "five_places.sort(reverse=True)\n", + "five_places" + ] } ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -528,7 +1033,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.7" + "version": "3.12.1" } }, "nbformat": 4,