-
Notifications
You must be signed in to change notification settings - Fork 2
/
dictionary.py
61 lines (45 loc) Β· 939 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
"""
Dictionary / HashMap / Map
f : integer --> anything
index: key --> value: anything
dictionary
key: anything --> value: anything
(unique) not unique
{}
"""
words = {
'i': 100,
'am': 20,
'batman': 87
}
print(type(words))
print(words['batman'])
words['batman'] = 100
print(words['batman'])
print(words)
words['hello'] = 1
print(words)
# removing value from dictionary
del words['hello']
print(words)
keys = words.keys()
print(keys)
print(type(keys))
values = words.values()
print(values)
print(type(values))
items = words.items()
print(items)
print(type(items))
# iterating over dict
print('\n\n\n')
# for key in words.keys(): # same as --> in words
# print(key)
# for value in words.values():
# print(value)
# for item in words.items():
# key = item[0]
# value = item[1]
# print(key + ' - ' + str(value))
for key, value in words.items():
print(key + ' - ' + str(value))