-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsolution_18.py
50 lines (44 loc) · 989 Bytes
/
solution_18.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Exercise 1.8
canton_list = [
"Zürich",
"Bern",
"Luzern",
"Uri",
"Schwyz",
"Obwalden",
"Nidwalden",
"Glarus",
"Zug",
"Fribourg",
"Solothurn",
"Basel-Stadt",
"Basel-Landschaft",
"Schaffhausen",
"Appenzell Ausserrhoden",
"Appenzell Innerrhoden",
"St. Gallen",
"Graubünden",
"Aargau",
"Thurgau",
"Ticino",
"Vaud",
"Valais",
"Neuchâtel",
"Geneva",
"Jura",
]
# 1. Sort the list alphabetically
# *******************************
# Looking at `help(list)`, we can see that there is a `sort` method that
# does just this:
canton_list.sort()
print(canton_list)
# 2. Reverse the list
# *******************
canton_list.reverse()
print(canton_list)
# Alternatively, you can use the slicing trick seen earlier:
print(canton_list[::-1])
# Note an important difference between these two methods: the first one
# reverses the original list, while the second one returns a copy of the
# list.