3.1
year_lists = [1980, 1981, 1982, 1983, 1984]
year_lists
[1980, 1981, 1982, 1983, 1984]
3.2
year_lists[2]
1982
3.3
max(year_lists)
1984
3.4
things = ['mozzarella', 'cinderella', 'salmonella']
3.5
things[1].capitalize()
‘Cinderella’
things
[‘mozzarella’, ‘cinderella’, ‘salmonella’]
3.6
things[0].upper()
‘MOZZARELLA’
3.7
surprise = ['Groucho', 'CHico', 'Harpo']
surprise[2] = surprise[2].lower()
surprise[2] = surprise[2][::-1].capitalize()
surprise
[‘Groucho’, ‘CHico’, ‘Oprah’]
3.10
e2f = {
'dog': 'chien',
'car': 'char',
'walrus': 'morse',
}
print(e2f['walrus'])
morse
f2e = dict()
for key, value in e2f.items():
f2e[value] = key
f2e
{‘char’: ‘car’, ‘chien’: ‘dog’, ‘morse’: ‘walrus’}
f2e['chien']
‘dog’
e2f.keys()
dict_keys([‘dog’, ‘car’, ‘walrus’])
life = {
'animals': {
'cats': ['Henri', 'Grumpy', 'Lucy'],
'octopi': {},
'emus': {},
},
'plants': {},
'other' : {},
}
life.keys()
dict_keys([‘animals’, ‘plants’, ‘other’])
life['animals'].keys()
dict_keys([‘cats’, ‘octopi’, ‘emus’])
life['animals']['cats']
[‘Henri’, ‘Grumpy’, ‘Lucy’]
Comments