-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictionary.py
45 lines (40 loc) · 1.12 KB
/
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
#Dictionary contains both key and value
my_dict={} #Empty Dictionary
my_dict={1:'Potato',2:'Onion'}
print(my_dict)
my_dict={'Name':'Milan','Middlename':'Loknath','Lastname':'Hazra'}
print(my_dict)
my_dict={1:[12,13],2:(5,6)}
print(my_dict)
#my_dict={[(1,'apple'),(2,'Adam')]} #You will get an error of unhashable list
my_dict={'Name':'Milan','Middlename':'Loknath','Lastname':'Hazra'}
print(my_dict['Name'])
print(my_dict['Lastname'])
my_dict={'Name':'Milan','Middlename':'Loknath','Lastname':'Hazra','Age':26}
print(my_dict)
a={'Name':'Milan','Middlename':'Loknath','Lastname':'Hazra','Age':26}
b=a.copy()
print(b)
print(a.get('Name'))
print(a.fromkeys('Name'))
print(a.items())
print(a.keys())
print(a.pop('Name'))
print(a)
print(a.popitem())
print(a.setdefault('Lastname'))
#print(a.update('Middlename'))
marks={}.fromkeys(['Maths','English','Science'],0)
print(marks)
print(marks)
squares={1:1,2:4,3:9,4:16,5:25,6:36,7:49,9:81}
print(squares)
print(1 in squares)
print(2 in squares)
for i in squares:
print(squares[i])
print(all(squares))
print(any(squares))
print(len(squares))
#print(cmp(squares,my_dict))
print(sorted(squares))