Dictionary Methods Flashcards
Definition dictionary
A dictionary is a collection which is unordered changeable and indexed.
Syntax curly brackets {“key”: “value”}
dict = {
“Brand”: “Ford”
“Year”: 1963
}
dict.copy()
Returns a copy of the dictionary.
dict.fromkeys()
Returns a dictionary with the specified keys and values.
dict.get()
Returns the value of the specified key.
dict.items
Returns a list containing a tulle for each key value pair.
dict.keys()
Returns a list containing the dictionaries keys.
dict.pop()
Removes an element with specified key.
dict.popitem()
Removes the last inserted key-value pair.
dict.setdefault()
Returns the value of the specified key. If the key doesn’t exist insert the key with specified value.
dict.update()
Updates the dictionary with the key-value pair.
dict.values()
Returns a list of all the values in the dictionary.
dict.clear()
Removes all elements from the dictionary.