Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyAddBook
#Python 2.7.17 #Python Address Book: demonstration of nested dictionary #this code is created by Rezaul Hoque on November 30,2021;contact: jewelmrh@yahoo.com #note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #Creating Dictionary print ('Creating Dictionary') a= { 'name': 'xyz', 'address': {'house':'00', 'road': '#2','city':'nul'}} print(a) #Add Item print('Add Item') a['contact']={'phone':'0###0','mail':'no@nono.com'} print(a) #Creating new nested dictionary using dict() constructor print('Creating new nested dictionary using dict() constructor') b=dict(origin={'nationality':'bbb','country':'nnnn'} ,name = 'efg', ) print(b) #Merging two dictionaries print('Merging two dictionaries') a.update(b) print(a) #Accessing values print('Accessing values') print(a['name']) print(a['address']['city']) print(a.get('address').get('road')) #Deleting item print('Deleting item') a.pop('contact') del a['address'] print(a) #iterate through nested dictionary print('Iterate through nested dictionary') for key, val in a.items(): if type(val) is dict: for inKey, inVal in val.items(): print(inKey+':', inVal) else: print(key+':', val)
run
|
edit
|
history
|
help
0
сщые
L100
working with strings
WoW
Rectangle Area
Filter dictionaries with specific keys
My Temp Converter
Temperature Converter
PySet
Aufgabe 15