Chapter 9: Dictionaries Flashcards
The algorithm used to implement Python dictionaries.
hash table
A mapping from a set of keys to their corresponding values.
An associative lookup
dictionary
A function used by a hash table to compute the location for a key.
hash function
A set of counters
histogram
A way of performing a computation.
implementation
Another name for a key-value pair.
item
An object that appears in a dictionary as the first part of a pair.
key
The representation of the mapping from a key to a value.
key-value pair
A dictionary operation that takes a key and finds the corresponding value.
lookup
When there are one or more loops “inside” of another loop. The inner loop runs to completion each time the outer loop runs once.
nested loops
An object that appears in a dictionary as the second part of a pair. This is more specific than our previous use of the word.
value
function that creates a dictionary with no items
dict()
dictionary notation
{key : value, etc}
notation to add item to dictionary
dict_name[key] = value
notation to print dictionary value
print(dict_name[key])
KeyError
Error when key not in dictionary
function that returns number of key-value pairs
len(dict_name)
operator to determine if KEY is in dictionary
in
key in dict_name = True
method to determine if value is in dictionary
.values()
vals = list(dict_name.values())
value in vals = True
built-in function to convert a character to its integer equivalent
ord()
way of performing a computation
implementation
dictionary method that takes a key and default value. If the key is in the dictionary, it returns the value. Else, returns default value
.get()
dict_name.get(key, default value) = value or default value
notation that returns a dictionary value
dict_name[key]
This static method returns a translation table usable for str.translate().
If there is only one argument, Character keys will be converted to ordinals (integers).
If two arguments, in the resulting dictionary each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
str.maketrans(x[, y[, z]])
str.makestrans(fromstring, tostring, deletestring))
string constant that specifies all the punctuation characters
need to import string module to use
no parentheses
string.punctuation
returns a string that has been created
such that any and all characters in s have been removed, and the remaining characters are translated using table (being a 256 character string giving the translation by ordinal indexing). If table is None, then
the translation is not performed.
string.translate(s, table[, deletechars])