Adding source code files for Chapter 6
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
# dictionary1.py
|
||||
|
||||
dict1 = {100:{'name':'John', 'age':24},
|
||||
101:{'name':'Mike', 'age':22},
|
||||
102:{'name':'Jim', 'age':21} }
|
||||
|
||||
print(dict1)
|
||||
print(dict1.get(100))
|
||||
@@ -0,0 +1,21 @@
|
||||
# dictionary2.py
|
||||
#defining inner dictionary 1
|
||||
student100 = {'name': 'John', 'age': 24}
|
||||
|
||||
#defining inner dictionary 2
|
||||
student101 = {}
|
||||
student101['name'] = 'Mike'
|
||||
student101['age'] = '22'
|
||||
|
||||
#assiging inner dictionaries 1 and 2 to a root dictionary
|
||||
dict1 = {}
|
||||
dict1[100] = student100
|
||||
dict1[101] = student101
|
||||
|
||||
#creating inner dictionary directly inside a root dictionary
|
||||
dict1[102] = {}
|
||||
dict1[102]['name'] = 'Jim'
|
||||
dict1[102]['age'] = '21'
|
||||
|
||||
print(dict1)
|
||||
print(dict1.get(102))
|
||||
@@ -0,0 +1,10 @@
|
||||
# dictionary3.py
|
||||
|
||||
dict1 = {100:{'name':'John', 'age':24},
|
||||
101:{'name':'Mike', 'age':22},
|
||||
102:{'name':'Jim', 'age':21} }
|
||||
|
||||
print(dict1.get(100))
|
||||
print(dict1.get(100).get('name'))
|
||||
print(dict1[101])
|
||||
print(dict1[101]['age'])
|
||||
@@ -0,0 +1,10 @@
|
||||
# dictionary4.py
|
||||
|
||||
dict1 = {100:{'name':'John', 'age':24},
|
||||
101:{'name':'Mike', 'age':22},
|
||||
102:{'name':'Jim', 'age':21} }
|
||||
|
||||
del (dict1[101]['age'])
|
||||
print(dict1)
|
||||
dict1[102].pop('age')
|
||||
print(dict1)
|
||||
Reference in New Issue
Block a user