Dictionary Flashcards
What is a dict (dictionary)?
in Python it is a data type and a data structure
an unordered collection of key: value pairs
consists of key: value pairs
a key: a string for us to grab the value. It is the key to access the value
a value:
Dictionary keys
a dictionary key must be immutable, cannot change
therefore we cannot use a list as a key since a list can be modified
a key should be descriptive
a key must be unique as it can only exist in the dictionary once. If you try to use the same key twice, the previous key: value pair will be lost
Dictionary methods
.get: takes in a key as an argument and returns None if the key does not exist. If it does exist it will return the value associated with the key
dict(key=value) is a built-in function that allows you to create a dictionary. Although, this is not commonly used