ADVANCED PROGRAMMING CONCEPTS - Python
Subject : ADVANCED PROGRAMMING CONCEPTS - Python
To solve assignments Please join Google Classroom.
Invitation of Google Classroom has been sent to your official email id.
Please accept the google classroom invitation through official email id.
Or directly by entering Class code of Google Classroom also
you can join Google Class room to solve assignments.
Class code of Google Classroom : 3ojdsjm
With kind regards,
SD Bhosale
- 5 minutes before
To know attendance: Click here
Session Python Programs:
-------------------------------
# Another way to make a copy is
# to use the built-in function dict().
# Example
# Make a copy of a dictionary with the dict() function:
thisdict = {
"brand": "Maruti",
"model": "k10",
"cc": 1000
}
mydict = dict(thisdict)
cdict=thisdict.copy()
print("New Dictionary",mydict)
print("Old Dictionary",thisdict)
print("cdict=",cdict)
print(type(mydict))
Output:
New Dictionary {'brand': 'Maruti', 'model': 'k10', 'cc': 1000}
Old Dictionary {'brand': 'Maruti', 'model': 'k10', 'cc': 1000}
cdict= {'brand': 'Maruti', 'model': 'k10', 'cc': 1000}
<class 'dict'>
--------------------------------------
# Nested Dictionaries
# A dictionary can also contain many dictionaries, this is called nested dictionaries.
# Example
# Create a dictionary that contain three dictionaries:
Maruti_Family = {
"v1" : {
"brand" : "Maruti_800",
"cc":800,
"color":"Gray"
},
"v2" : {
"brand" : "Maruti_K10",
"cc":1000,
"color":"Red"
},
"v3" : {
"brand" : "Maruti_Swift",
"cc":1200,
"color":"White"
}
}
print(Maruti_Family)
Output:
{'v1': {'brand': 'Maruti_800', 'cc': 800, 'color': 'Gray'}, 'v2': {'brand': 'Maruti_K10', 'cc': 1000, 'color': 'Red'}, 'v3': {'brand': 'Maruti_Swift', 'cc': 1200, 'color': 'White'}}
-------------------------------
# if you want to nest three dictionaries that already exists as dictionaries:
# Example
# Create three dictionaries, then create one dictionary
# that will contain the other three dictionaries:
v1= {
"brand": "Maruti_800",
"cc": 800,
"color": "Gray"
}
v2 = {
"brand" : "K10",
"cc":1000,
"color":"Red"
}
v3 = {
"brand" : "Swift",
"cc":1200,
"color":"White"
}
Maruti_Family = {
"c1":v1,
"c2":v2,
"c3":v3
}
print(Maruti_Family)
Output:
{'c1': {'brand': 'Maruti_800', 'cc': 800, 'color': 'Gray'}, 'c2': {'brand': 'K10', 'cc': 1000, 'color': 'Red'}, 'c3': {'brand': 'Swift', 'cc': 1200, 'color': 'White'}}
Google Meet Video Session :
High Resolution:
No comments:
Post a Comment