Dictionary Flashcards
.get()
Used to get the value of any specified key from a dictionary.
Example:
d.get(key) - returns value
.copy()
Used on objects to create copies of them
Expample: d.copy()
Enumerate function
Is a built in function that allows you to iterate over elements in a sequence(list, tuple, string etc) while keeping track of the index and the value of each element. Returns an enumerate object that produces pairs for index-value tuples
Syntax for enumerate function
enumerate(iterable, start=0)
start is optional
dictionaries library
from collections import defaultdict
Dictionary comprehension
animalList = [(1:a), (2:b)]
animals {key:value for key, value in animalList}
How to turn a dictionary into a list
list(dictionary.items())