-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdictionaries.py
More file actions
62 lines (47 loc) · 1.23 KB
/
dictionaries.py
File metadata and controls
62 lines (47 loc) · 1.23 KB
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
# Dictionary stores pairs of data together - a key and a value
my_dict = {}
grades = {"Ana": 5, "Kolya": 3, "Petya": 4}
num_of_students = len(grades)
# We can add change entries
grades["Misha"] = "B"
grades["Kolya"] = 2
# Test if key in dictionary
an = "Ana" in grades
ko = "Kolya" in grades
# Remove an entry
del(grades["Misha"])
# Get set of keys or values as iterable for loop
grades.keys()
grades.values()
animals = { 'a': ['aardvark'], 'b': ['baboon'], 'c': ['coati']}
animals['d'] = ['donkey']
animals['d'].append('dog')
animals['d'].append('dingo')
def how_many(aDict):
'''
aDict: A dictionary, where all the values are lists.
returns: int, how many values are in the dictionary.
'''
# Your Code Here
i = 0
for value in aDict.values():
i += len(value)
return i
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
lens = {}
for value in aDict:
lens[value] = (len(aDict[value]))
m = 0
i = ""
for key, value in lens.items():
if m <= value:
m = value
i = key
print(i)
return i
biggest(animals)