Skip to content
Open

Main #16

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions lists.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,67 @@
"\n",
"Complete Exercise 3-8 in Matthes (2023, p. 45)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3-8. Seeing the World: Think of at least five places in the world you’d like to visit.\n",
"• 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; just print it as a raw Python list.\n",
"• Use sorted() to print your list in alphabetical order without modifying the actual list.\n",
"• Show that your list is still in its original order by printing it.\n",
"• Use sorted() to print your list in reverse-alphabetical order without chang- ing the order of the original list.\n",
"• Show that your list is still in its original order by printing it again.\n",
"• Use reverse() to change the order of your list. Print the list to show that its order has changed.\n",
"• Use reverse() to change the order of your list again. Print the list to show it’s back to its original order.\n",
"• Use sort() to change your list so it’s stored in alphabetical order. Print the list to show that its order has been changed.\n",
"• Use sort() to change your list so it’s stored in reverse-alphabetical order. Print the list to show that its order has changed."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['Portugal', 'Greece', 'Chile', 'Argentina', 'Italy']\n",
"['Argentina', 'Chile', 'Greece', 'Italy', 'Portugal']\n",
"['Portugal', 'Greece', 'Chile', 'Argentina', 'Italy']\n",
"['Portugal', 'Italy', 'Greece', 'Chile', 'Argentina']\n",
"['Portugal', 'Greece', 'Chile', 'Argentina', 'Italy']\n",
"['Italy', 'Argentina', 'Chile', 'Greece', 'Portugal']\n",
"['Portugal', 'Greece', 'Chile', 'Argentina', 'Italy']\n",
"['Argentina', 'Chile', 'Greece', 'Italy', 'Portugal']\n",
"['Portugal', 'Italy', 'Greece', 'Chile', 'Argentina']\n"
]
}
],
"source": [
"travel = [\"Portugal\", \"Greece\", \"Chile\", \"Argentina\", \"Italy\"]\n",
"print(travel)\n",
"\n",
"print(sorted(travel))\n",
"print(travel)\n",
"\n",
"print(sorted(travel, reverse=True))\n",
"print(travel)\n",
"\n",
"travel.reverse()\n",
"print(travel)\n",
"\n",
"travel.reverse()\n",
"print(travel)\n",
"\n",
"travel.sort()\n",
"print(travel)\n",
"\n",
"travel.sort(reverse=True)\n",
"print(travel)"
]
}
],
"metadata": {
Expand Down