-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dictionary.py
63 lines (44 loc) · 1023 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
62
"""
Created By : Vikram Markali
"""
print('create empty dictionary...')
Dict = {}
print(Dict)
print('Create dictionary with pair....')
dict1 = {"Name":"Vikram","Age":20,"Marks":95}
print(dict1)
print('create dictionary using dict() method....')
dict2 = dict({1:'c',2:'c++',3:'java'})
print(dict2)
dict3 = dict([(1,'vikram'),(2,'vaishnavi'),(3,'suraj')])
print(dict3)
# Adding dictionary elements....
print('\n****ADDING & UPDATING****')
sub = {1:'c++',2:'java',3:'python'}
print(sub)
sub[3] = 'javascript'
sub[4] = 'python'
print(sub)
# Accessing dictionary elements....
print('\n****ACCESS****')
print(sub[2])
print(sub[3])
# by using loop....
for i in sub:
print(i) #display keys....
for i in sub.keys():
print(i)
for i in sub:
print(sub[i]) #print values....
for i in sub.values():
print(i)
for i in sub.items():
print(i) #print pair...
print("\n****DELETING****")
print(sub)
del sub[3]
print(sub)
# delete dictionary...
# print(sub)
# del sub
# print(sub)