Create AI Video
Create AI Video

Dictionaries

ARCHANA BHARATHI P 23IT004
2024-10-13 21:48:12
Dictionary is an unordered collection of elements. An element in dictionary has a key: value pair. All elements in dictionary are placed inside the curly braces i.e. { }Elements in Dictionaries are accessed via keys and not by their position. The values of a dictionary can be any data type. Keys must be immutable data type .Operations on dictionary:Accessing an element :Accessing the elements by using keysUpdate :Assigning a new value to key. It replaces the old value by new valueAdd element :Add new element in to the dictionary with keyMembershipMethods in dictionary:1. a.copy( ) :It returns copy of the dictionary2. a.items() :Return a new view of the dictionary's items. It displays a list of dictionary's (key, value) tuple pairs.3. a.keys() :It displays list of keys in a dictionary4. a.values() :It displays list of values in dictionary5. a.pop(key) :Remove the element with key and return its value from the dictionary6. a.update(dictionary) :It will add the dictionary with the existing dictionary7. fromkeys() :It creates a dictionary from key and values8. len(a) :It returns the length of the list9. clear() :Remove all elements form the dictionary10. del(a) :It will delete the entire dictionary

Related Videos