Data Structures in Python- Dictionaries

 Ref Videohttps://www.youtube.com/watch?v=rpsYzPv1HiQ

Dictionaries

  • A Python dictionary is a data structure that stores data in key-value pairs, where each key is unique and is used to retrieve its associated value. 
  • It is mainly used when you want to store and access data by a name (key) instead of by position like in a list.



  • Ordered---Yes, it is ordered
  • Allow Duplicates---Keys are unique and Values allow duplicates
  • Indexed---Not indexed. You can access values by using their keys, not indexes.
  • Mutable---Yes, values can be updated in Dictionary


  • Methods in Dictionaries

    get() ---Returns value safely, gives none if missing.
    keys()---Returns all the keys in your dictionary
    Values()---Returns all the values in your dictionary
    items()--- Returns all (Key, value) pair of your dictionary
    update()---adds new keys and updates existing ones using another dictionary
    pop()--- Removes a key form the dictionary and returns its value
    popitem()---retuns and deletes the most recent key value pair from the dictionary
    fromkey()--builds a new dictionary where all keys get the same default value

    Comments