diff --git a/data_structures/dictionaries.py b/data_structures/dictionaries.py new file mode 100644 index 0000000..cc7726a --- /dev/null +++ b/data_structures/dictionaries.py @@ -0,0 +1,28 @@ +#Creation of a dictionary +dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} +print ("dict['Name']: ", dict['Name']) +print ("dict['Age']: ", dict['Age']) + +#which will give the result as +#dict['Name']: Zara +#dict['Age']: 7 + +#Updating a dictionary + +dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} +dict['Age'] = 8; # update existing entry +dict['School'] = "DPS School" # Add new entry + +print ("dict['Age']: ", dict['Age']) +print ("dict['School']: ", dict['School']) + +#which will give as result +#dict['Age']: 8 +#dict['School']: DPS School + +#Deletion of a dictionary +dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} + +del dict['Name'] # remove entry with key 'Name' +dict.clear() # remove all entries in dict +del (dict) # delete entire dictionary