-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
50 lines (40 loc) · 1.11 KB
/
dictionary.py
File metadata and controls
50 lines (40 loc) · 1.11 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
#Dictionary -: unoredered collection of data with key value pair
dict1={'Name':'Panakj','age':18,1:1729}
print(dict1)
print(len(dict1))
#dictionary by dict method
example1=dict(name='Pankaj Kumar',age=18)
print('dictionary with dict method',example1)
#No indexing present in dictionary
#here we use key
print("data excess by key not by index :" ,example1['name'])
#in dictionary (string,list)
example2={
'name':'Pankaj Kumar Agrawal', 'age':18,
'fav_movie':['Marvel Universe','ABCD2']
,1:1729
}
print(example2)
#to print all key value
for i in example2:
print(type(i))
print("keys of example2", i)
#by key value
for i in example1.keys():
print("key of example1", i)
print(type(i))
#To read value from dictonary
for i in example2.values():
print(i)
#to print item : it rerturn key-value pair
for i in example2.items():
print(i)
#update method:
example3={'a':"all",'22':'a22'}
example2.update(example3)
print(example2)
#pop method : it return value corresponding to that key
print(example3.pop('22'))
print(example3)
#popitems method : it return key-value pair
print(example2.popitem())