Remove All Elements from a Dictionary in Python
You can remove all elements from a dictionary using the clear
method:
dct = {
'a': 1,
'b': 2,
'c': 3
}
dct.clear()
print(dct) # {}
Given a dictionary:
dct = {
'x': 1,
'y': 2,
'z': 3
}
Clean it up.
The following code is given:
dct = {
1: 'text1',
2: 'text2',
3: 'text3'
}
dct.clear()
dct[4] = 'text4'
print(dct)
Tell me what will be output to the console.