forked from techstay/python-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter3.py
More file actions
69 lines (52 loc) · 939 Bytes
/
chapter3.py
File metadata and controls
69 lines (52 loc) · 939 Bytes
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Q1
year_list = [1994, 1995, 1996, 1997, 1998]
# Q2
third_year = year_list[3]
# Q3
max_year = max(year_list)
# Q4
things = ['mozzarella', 'cinderella', 'salmonella']
# Q5
things[1].capitalize()
print(things)
# Q6
things[0].upper()
print(things)
# Q7
del things[-1]
print(things)
# Q8
surprise = ['Groucho', 'Chico', 'Harpo']
surprise[-1] = surprise[-1].lower()
surprise[-1] = surprise[-1][::-1]
surprise[-1] = surprise[-1].capitalize()
# Q10
e2f = {'dog': 'chien', 'cat': 'chat', 'walrus': 'norse'}
print(e2f)
# Q11
print(e2f['walrus'])
# Q12
f2e = {}
for k, v in e2f.items():
f2e.setdefault(v, k)
print(f2e)
# Q13
print(f2e['chien'])
# Q14
set(e2f.keys())
# Q15
life = {
'animals': {
'cats': ['Henri', 'Grumpy', 'Lucy'],
'octopi': {},
'emus': {}
},
'plants': {},
'others': {}
}
# Q16
print(life.keys())
# Q17
print(life['animals'].keys())
# Q18
print(life['animals']['cats'])