From 53b4855f1f382d907f3b8e8c5ed6afd66157787c Mon Sep 17 00:00:00 2001 From: jaideep6214 <43785047+jaideep6214@users.noreply.github.com> Date: Wed, 9 Oct 2019 21:05:31 +0530 Subject: [PATCH] Concept of Dictionary using python 3 --- data_structures/dictionaries.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 data_structures/dictionaries.py 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