Chapter 9: Dictionaries Flashcards

1
Q

The algorithm used to implement Python dictionaries.

A

hash table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

A mapping from a set of keys to their corresponding values.
An associative lookup

A

dictionary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A function used by a hash table to compute the location for a key.

A

hash function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A set of counters

A

histogram

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A way of performing a computation.

A

implementation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Another name for a key-value pair.

A

item

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

An object that appears in a dictionary as the first part of a pair.

A

key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The representation of the mapping from a key to a value.

A

key-value pair

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A dictionary operation that takes a key and finds the corresponding value.

A

lookup

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When there are one or more loops “inside” of another loop. The inner loop runs to completion each time the outer loop runs once.

A

nested loops

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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.

A

value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

function that creates a dictionary with no items

A

dict()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

dictionary notation

A

{key : value, etc}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

notation to add item to dictionary

A

dict_name[key] = value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

notation to print dictionary value

A

print(dict_name[key])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

KeyError

A

Error when key not in dictionary

16
Q

function that returns number of key-value pairs

A

len(dict_name)

17
Q

operator to determine if KEY is in dictionary

A

in
key in dict_name = True

18
Q

method to determine if value is in dictionary

A

.values()
vals = list(dict_name.values())
value in vals = True

19
Q

built-in function to convert a character to its integer equivalent

A

ord()

20
Q

way of performing a computation

A

implementation

21
Q

dictionary method that takes a key and default value. If the key is in the dictionary, it returns the value. Else, returns default value

A

.get()
dict_name.get(key, default value) = value or default value

22
Q

notation that returns a dictionary value

A

dict_name[key]

23
Q

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.

A

str.maketrans(x[, y[, z]])

str.makestrans(fromstring, tostring, deletestring))

24
Q

string constant that specifies all the punctuation characters
need to import string module to use
no parentheses

A

string.punctuation

25
Q

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.

A

string.translate(s, table[, deletechars])