-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
69 lines (50 loc) · 1.39 KB
/
Copy pathdictionary.py
File metadata and controls
69 lines (50 loc) · 1.39 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
student={'name':'abc','rolll_no' : 1,'mark':[10,20,30]}
print(student)
print(type(student))
print(type(student))
#accessing dicg items
student={'name':'abc','rolll_no' : 1,'mark':[10,20,30]}
print(student['name'])
print(student['mark'])
#accessing using get method
student={'name':'abc','rolll_no' : 1,'mark':[10,20,30]}
print(student.get('mark'))
#accessing keys
print(student.keys())
#add a record
student={'name':'abc','rolll_no' : 1,'mark':[10,20,30]}
student['age']=12
print(student)
#accessing values
student={'name':'abc','rolll_no' : 1,'mark':[10,20,30]}
print(student.values())
#accessing items
student={'name':'abc','rolll_no' : 1,'mark':[10,20,30]}
student.popitem()
print(student)
#using delete method
student={'name':'abc','roll_no' :1,'mark':[10,20,30]}
del student['roll_no']
print(student)
#for loop in dict
d1={'fruits':'apple','number':1,'color':'red','price':10}
for i in d1:
print(d1 [i])
#using function
d1={'fruits':'apple','number':1,'color':'red','price':10}
for i in d1.keys():
print(i)
# using function
d1 = {'fruits': 'apple', 'number': 1, 'color': 'red', 'price': 10}
for i,j in d1.items():
print(i,j)
#making a copy method
#1 copy method
new=d1.copy()
print(new)
#nested dictionaries
main={'student':{'name':'abc','rolll_no' : 1,'mark':[10,20,30]},'d1':{'fruits': 'apple', 'number': 1, 'color': 'red', 'price': 10}}
print(main)
#dict method
new1=dict(d1)
print(new1)