-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionairies.py
More file actions
48 lines (34 loc) · 814 Bytes
/
dictionairies.py
File metadata and controls
48 lines (34 loc) · 814 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
def main():
animals = {'a': ['aardvark'], 'b': ['baboon'], 'c': ['coati']}
animals['d'] = ['donkey']
animals['d'].append('dog')
animals['d'].append('dingo')
print(how_many(animals))
print(biggest(animals))
def how_many(aDict):
how_many = 0
for elem in aDict :
how_many += len(aDict[elem])
return how_many
def biggest(aDict):
biggest = []
for key in aDict :
if len(aDict[key]) > len(biggest):
biggest = key
return biggest
"""
print(applyEachTo([inc, square, halve, abs], 3.0))
def applyEachTo(L, x):
result = []
for i in range(len(L)):
result.append(L[i](x))
return result
def square(a):
return a*a
def halve(a):
return a/2
def inc(a):
return a+1
"""
if __name__ == '__main__':
main()