-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_dicnatoryOperation.py
More file actions
62 lines (41 loc) · 978 Bytes
/
13_dicnatoryOperation.py
File metadata and controls
62 lines (41 loc) · 978 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#Dictionaries in python
myDict = {"name": "aditya", "age":"19", "year":"2nd"}
print(myDict)
#print Each Element in dictionaries
print(myDict["name"])
#key is no present still can't throw error
print(myDict.get("blood"))
#only print keys
print(myDict.keys(),"\n")
#with for
for key in myDict.keys():
print(myDict[key])
#direct adding
myDict['post'] = "manager"
#For Values
print(myDict.values())
for key, values in myDict.items():
print(f'{key} : {values}')
#dictionary methods :
myDict1 = {23:2, 24:1, 25:3}
myDict2 = {1 : 12, 2: 13}
myDict1.update(myDict2)
print(myDict1)
myDict1.pop(24)
print(myDict1)
myDict2.popitem()
print(myDict2)
myDict.clear()
print(myDict)
#deleting key value pairs
del myDict1[23]
print(myDict1)
#checking Existance
print('name' in myDict1)
#Advance python concepts
#nested dictionary
nested_dict = {
'dict1' :{"app":"insta", "foll":23},
'dict2' :{"app": "WhatsApp", "foll":65}
}
print(nested_dict['dict1']['app'])