-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLec5-Problem11-biggest.py
44 lines (29 loc) · 1.01 KB
/
Lec5-Problem11-biggest.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
animals = { 'a': ['aardvark'], 'b': ['baboon'], 'c': ['coati']}
animals['d'] = ['donkey']
animals['d'].append('dog')
animals['d'].append('dingo')
def biggest(aDict):
'''
aDict: A dictionary, where all the values are lists.
returns: The key with the largest number of values associated with it
'''
# Your Code Here
if len(aDict) > 0:
b = 0
for i in range(len(aDict.keys())):
if len(aDict.values()[i]) > len(aDict.values()[b]):
b = i
return aDict.keys()[b]
else: return None
def biggest2(aDict):
'''
aDict: A dictionary, where all the values are lists.
returns: The key with the largest number of values associated with it
'''
result = None
biggestValue = 0
for key in aDict.keys():
if len(aDict[key]) >= biggestValue:
result = key
biggestValue = len(aDict[key])
return result