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’})
2
Q
function to remove a key along with its value
A
capitals.pop(‘India’)
3
Q
function to clear dictionary
A
capitals.clear()
4
Q
function to print the keys in the dictionary
A
print(capitals.keys())
5
Q
function to print the values of a dictionary
A
print(capitals.values())
6
Q
Function to print all items in dictionary
A
print(capitals.items())
7
Q
for loop to print items in dictionary
A
for key, value in capitals.items():
print(key, value)