From 52af311e950434335afca9a8c3d1128e3c7eef2c Mon Sep 17 00:00:00 2001 From: Nika Lea Tomicic Date: Mon, 3 Feb 2025 01:50:54 +0000 Subject: [PATCH] Main HW 1 Tomicic --- lists.ipynb | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/lists.ipynb b/lists.ipynb index 38de076..45b1311 100644 --- a/lists.ipynb +++ b/lists.ipynb @@ -1019,11 +1019,69 @@ "\n", "Complete Exercise 3-8 in Matthes (2023, p. 45)." ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['santiago', 'istanbul', 'florence', 'tokyo', 'beirut']\n", + "['beirut', 'florence', 'istanbul', 'santiago', 'tokyo']\n", + "['santiago', 'istanbul', 'florence', 'tokyo', 'beirut']\n", + "['santiago', 'istanbul', 'florence', 'tokyo', 'beirut']\n", + "['beirut', 'tokyo', 'florence', 'istanbul', 'santiago']\n", + "['santiago', 'istanbul', 'florence', 'tokyo', 'beirut']\n", + "['beirut', 'florence', 'istanbul', 'santiago', 'tokyo']\n", + "['tokyo', 'santiago', 'istanbul', 'florence', 'beirut']\n" + ] + } + ], + "source": [ + "#Exercise 3-8 work shown\n", + "\n", + "#Storing five places in a list called places\n", + "places = [\"santiago\", \"istanbul\", \"florence\", \"tokyo\", \"beirut\"]\n", + "\n", + "#Printing the list in raw form\n", + "print(places)\n", + "\n", + "#Sorting list in alphabetical order\n", + "print(sorted(places))\n", + "\n", + "#Print list to show the original order is unchanged\n", + "print(places)\n", + "\n", + "#Change the order of the list to reverse alphabetical\n", + "sorted(places,reverse=True)\n", + "\n", + "#Change the order of the list back to original order:\n", + "print(places)\n", + "\n", + "#Change order of list and print to show change:\n", + "places.reverse()\n", + "print(places)\n", + "\n", + "#Change order of list to reverse and print change:\n", + "places.reverse()\n", + "print(places)\n", + "\n", + "#Use sort to change to store list in alphabetical order:\n", + "places.sort()\n", + "print(places)\n", + "\n", + "#Use sort to change list to reverse alphabetical order:\n", + "places.sort(reverse=True)\n", + "print(places)\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".venv", "language": "python", "name": "python3" },