Simultaneously replacing all values of a dictionary to zero python
Be warned, if the order of your keys matter the solution may not be suitable as it seems to reorder.
To stop this from happening use list comprehension:
aDictionary = { x:0 for x in aDictionary}
Note: It's only 2.7.x and 2.x exclusive
Thanks @akaRem for his comment :)
a = dict.fromkeys( a.iterkeys(), 0 )
You want dict.fromkeys()
:
a = dict.fromkeys(a, 0)