Python - Dictionary Methods Flashcards
Return - none
Args - none
___________
Clears the dictionary
dict.clear()
Return - shallow copy of dictionary
Args - none
___________
returns a shallow copy of the dictionary.
dict.copy()
Return - dictionary (with keys but no values)
Args - iterable
___________
returns a new dictionary with the given sequence of elements as the keys of the dictionary.
If the value argument is set, each element of the newly created dictionary is set to the provided value.
dict.fromkeys(keys)
Return - dictionary value
Args - ( key, optional value to return if key not found)
___________
returns the value for the specified key if key is in dictionary.
dict.get( ‘key name’ )
Return - view object of key-val pairs
Args - none
___________
returns a view object that displays a list of dictionary’s (key, value) tuple pairs.
dict.items()
Return - view object of list of keys
Args - none
___________
returns a view object that displays a list of all the keys in the dictionary
dict.keys()
Return - value at specified key
Args - key
___________
removes and returns an element from a dictionary having the given key.
dict.pop( ‘key’ )
Return - view object of list of values
Args - none
___________
method returns a view object that displays a list of all the values in the dictionary.
dict.values()
Return - none
Args - another dict or some other iterable of key-val pairs (like an iterable of tuples)
___________
adds element(s) to the dictionary if the key is not in the dictionary. If the key is in the dictionary, it updates the key with the new value.
dict.update( dict or iterable ]
Return - bool
Args - iterable
___________
returns True if any element of an iterable is True. If not, any() returns False.
dict.any( iterable )
Return - bool
Args - iterable
___________
method returns True when all elements in the given iterable are true. If not, it returns False.
dict.all( iterable )
Return - none
Args - iterable of tuples
___________
constructor creates a dictionary in Python.
dict( [ iterable of tuples ] )
Return - enumerate object
Args - iterable, optional start value
___________
method adds counter to an iterable and returns the enumerate object
enumerate( iterable )
Return - list
Args - iterable, optional reverse=True
___________
method returns a sorted list from the given iterable.
sorted( iterable )