Chapter 11 Dictionaries Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

A dictionary contains a collection of indices which are called?

A

Keys

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

The association of a key and a value is called a? Or sometimes a?

A

Key-value-pair or sometimes item

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

In a dictionary, each key “ “ a value

A

maps to

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

Dictionaries are always in alphabetical order. True or False

A

False
Dictionary elements are in no particular order, unlike lists.

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

” “ is a method that takes a key and default value. If the key appears in the dictionary, the method returns the corresponding value; otherwise, it returns the default value.

A

.get

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

To traverse the keys in alphabetical order, you can use
the built-in function

A

sorted

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

Define singleton

A

A list that contains a single element.

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

How do I tell Python that I want the variable outside of the function to be used inside the function without alterations?

A

Use the global statement
»> been_called = False
»> def example2():
global been_called
been_called = True

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

What is wrong with this code?
»> count = 0
»>def counter():
count = count + 1
print(count)

A

The global variable was not declared inside the function.
Corrected version:
»> def counter():
global count
count += 1
print(count)

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

True or False:
If a global variable refers to an immutable value, you can modify the value without declaring the variable.

A

False. The value must be mutable.
Example:
known = {0:0, 1:1}

def example():
known[2] = 1

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

4 suggestions for debugging large datasets are:

A
  1. Scale down the input
  2. Check summaries and types
  3. Write self-checks
  4. Format the output
    Page 111-112 of Think Python
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A relationship in which each element of one set corresponds to an element of
another set.

A

mapping

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

A mapping from keys to their corresponding values

A

dictionary

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

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

A

key

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

In a dictionary, another name for a key-value pair

A

item

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

The representation of the mapping from a key to a value

A

key-value pair

17
Q

An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word.

A

value

18
Q

The algorithm used to implement Python dictionaries.

A

hashtable

19
Q

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

A

hash function

20
Q

A way of performing a computation.

A

implementation

21
Q

A type that has a hash function. Immutable types like integers, floats and strings are “______”; mutable types like lists and dictionaries are not.

A

hashable

22
Q

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

A

lookup

23
Q

A dictionary operation that takes a value and finds one or more keys that map to it.

A

reverse lookup

24
Q

A statement that (deliberately) raises an exception

A

raise statement

25
Q

A list (or other sequence) with a single element.

A

singleton

26
Q

A diagram that shows every frame created during the execution of a program,
with an arrow from each caller to each callee.

A

Call graph

27
Q

A computed value stored to avoid unnecessary future computation.

A

memo

28
Q

A variable defined outside a function. Can be accessed from any function.

A

global variable

29
Q

A boolean variable used to indicate whether a condition is true.

A

flag

30
Q

A statement like global that tells the interpreter something about a variable.

A

declaration