Posts

Showing posts with the label Dictionaries - Data Structures

Python3 Dictionaries DS

Python Data Structures : Dictionaries Dictionary          Python dictionary is an unordered collection of items. While other compound data types have only value as an element, a dictionary has a key : value pair. Dict Creation :   Eg:         #empty dictionary        my_dict={}         #dictionary with integers as keys        my_dict={1:'a',2:'b"}        print(my_dict)                 #dictionary with mixed keys        my_dict={'name':'satish',1:['abc','xy']}        print(my_dict)           #create empty dictionary using dict( )        my_dict=dict()        my_dict=dict([(1,'abc'),(2,'xy')])      #create a dict with list of tuples        print(my_dict) output:   {1:'a',2:'b'}               {'name':'satish',1:['abc','xy']}               {1:'abc',2:'xy'}    Dict Access : Eg:        my_dict={'name': 'suma','year':2020}        print(my_d