Thursday, March 11, 2021

Important Points to Remember : Dictionary Objects in Python ( syntax , usage , methods , behaviour etc )

 

  Points to Remember: Dictionary Objects in Python




 

1) A dictionary represents a group of elements arranged in the form of key-value pairs. In the dictionary object , the first element is considered as the 'key' and the immediate next element is considered as its associated 'value' .

 

2) The Key and Value Pairs should be written inside a dictionary by separating them with the help of a colon (:) operator. Each pair should be separated with the help of a comma sign. All the key-value pairs of the dictionary should be written inside curly braces { }

 

3) Indexing and Slicing are not useful to access the elements of a dictionary

 

4) While inserting a new element or modifying the existing element, it is preferable to use the given format:

 

dict(key) = Value

 

5) The keys of a dictionary should be unique and must be Immutable which means that once the data for the Keys is assigned, one cannot change the data type of the elements inside the dictionary.

 

6) The keys of a dictionary should be unique and belong to immutable datatype . The value associated with the key should be unique and should be immutable in nature.

 

7) The get(k,v) method returns the value upon taking the key 'k' . If the key is not found in the dictionary , then it will return a default value 'v'

 

8) The update({k:v}) method stores the key 'k' and its value 'v' pair into an existing dictionary

 

9) The dict() method converts a list or tuple or a zip object into a dictionary

 

10) The zip() method is useful to convert the sequences like lists into a zip class object

 

11) An ordered dictionary is a dictionary but it will keep the order of the elements

 

12) Ordered Dictionaries are created using the OrderedDict() method of collections module .

 

No comments:

Post a Comment