-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictioanry.py
More file actions
41 lines (29 loc) · 756 Bytes
/
dictioanry.py
File metadata and controls
41 lines (29 loc) · 756 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
d={"Tom":734342343,"rob":21325245,"joe":3424234324}
d
{'Tom': 734342343, 'rob': 21325245, 'joe': 3424234324}
d["Tom"]
734342343
# Changin the value in a dictionary
d["sam"]=21321432523
d
{'Tom': 734342343, 'rob': 21325245, 'joe': 3424234324, 'sam': 21321432523}
d["rob"]=132123123
d
{'Tom': 734342343, 'rob': 132123123, 'joe': 3424234324, 'sam': 21321432523}
del d["sam"]
d
{'Tom': 734342343, 'rob': 132123123, 'joe': 3424234324}
# displaying the dictionary values
# 1. One way
for key in d:
print("Key is: ",key," value is ",d[key])
# 2. Two way
for key , value in d.items():
print("Key is ",key, " Value is ",value)
# Search for a value in dictionary
"tom" in d
False
"Tom" in d
True
# Wipe out the data in a dictionary
d.clear()