dictionaries Flashcards

1
Q

function to add a dictionary or update an existing item in the dictionary

A

add = capitals.update({‘Germany’: ‘Berlin’})
existing = capitals.update({‘USA’:’Las Vegas’})

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

function to remove a key along with its value

A

capitals.pop(‘India’)

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

function to clear dictionary

A

capitals.clear()

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

function to print the keys in the dictionary

A

print(capitals.keys())

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

function to print the values of a dictionary

A

print(capitals.values())

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

Function to print all items in dictionary

A

print(capitals.items())

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

for loop to print items in dictionary

A

for key, value in capitals.items():
print(key, value)

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