Page 1 :
Dictionary:- Python dictionary is an unordered collection of items where each, item is a key:value pair. It is also refer to a dictionary as a mapping between a, set f keys/indices and a set of values., Important features of dictionaries: Each key maps to a value., Each key is separated from its values by a colon sign, the items are, separated by commas and the entire dictionary is enclosed in curly, braces., Keys are unique within a dictionary while values may not be., The value of dictionary can be of any type, but the keys must be of an, immutable data type such as strings, numbers or tuples., Dictionary is mutable. We can add new items or change the value of, existing items., Creating a Dictionary, Syntax:Dictionary name= {‘key1’:’value’, ‘key2’:’value’……… ‘keyn’:’valuen}, Methods to create dictionary:, 1. D1= { }, 2. D2= {key:value}, 3. D=dict(), Accessing elements in a dictionary:, To access dictionary elements you can use the familiar square brackets along, with the key to obtain its values:, Syntax:- print(dictionaryname=[‘key’]), Traversing a dictionary:, Traversing a dictionary means accessing each element of a dictionary. This can, be done by using for loop., Syntax:- for I in dictionary name:, Print(I, dictionaryname[I]), Do practice in rough copy:, 1. Create a dictionary of 5 key:value pair., 2. Access the two elements from a dictionary., 3. Traversing a dictionary.