Python Dict Methods Flashcards

1
Q

Removes all the elements from the dictionary.

A

clear()

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

Returns a copy of the dictionary.

A

copy()

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

Returns a dictionary with the specified keys and value.

A

fromkeys()

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

Returns the value of the specified key.

A

get()

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

Returns a list containing a tuple for each key value pair.

A

items()

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

Returns a list containing the dictionary’s keys.

A

keys()

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

Removes the element with the specified key.

A

pop()

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

Removes the last inserted key-value pair.

A

popitem()

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

Returns the value of the specified key. If the key does not exist: insert the key, with the specified value.

A

setdefault()

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

Updates the dictionary with the specified key-value pairs.

A

update()

car = {
  "brand": "Ford"
}

car.update({"color": "White"})

# Output 
{
    "brand": "Ford",
    "color": "White"
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Returns a list of all the values in the dictionary.

A

values()

car = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}

car.values()

# Output
dict_values(['Ford', 'Mustang', 1964])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly