-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdictionary.py
68 lines (53 loc) Β· 974 Bytes
/
dictionary.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Lists / Arrays
f : Integer --> Anything
index --> value
(unique) --> (not unique)
Dictionary / HashMap / HashTable / Map
Mutable
not immutable
f : Anything --> Anything
key --> value
(unique) --> (not unique)
"""
words = {
'i': 100,
'am': 50,
'batman': 2
}
print(type(words))
print(words)
val = words['am']
print(val)
print(type(val))
print(words.get('i'))
print(words)
words['i'] = 200
print(words)
words['ball'] = 5
print(words)
words['ball'] = 80
print(words)
del words['ball']
print(words)
# del words
# print(words)
keys = words.keys()
print(type(keys))
print(keys, end='\n\n')
values = words.values()
print(type(values))
print(values, end='\n\n')
items = words.items()
print(type(items))
print(items)
for key in words.keys():
print(key)
s = 0
for value in words.values():
s += value
print(s)
for item in words.items():
key = item[0]
value = item[1]
print('key: ' + str(key) + ' value: ' + str(value))