David Wyde

Python dict Quiz

2013-12-13

What's wrong with the following Python statement? How do you undo the damage?

dict = {123: 'abc'}

Answer: it clobbers the built-in dict type with a dictionary instance!

You can restore the original state in a few ways, including:

dict = {}.__class__
dict = type({})
dict = __builtins__.dict
dict = (lambda:0).func_globals.__class__