9

I have a list to be used as keys for the dictionary and every value corresponding to the keys is to be initialized to 0.

kramer
  • 677
  • 2
  • 8
  • 17

1 Answers1

23

You can do with dict.fromkeys

In [34]: dict.fromkeys(range(5),0)
Out[34]: {0: 0, 1: 0, 2: 0, 3: 0, 4: 0}
In [35]: dict.fromkeys(['a','b','c'],0)
Out[35]: {'a': 0, 'b': 0, 'c': 0}
Rahul K P
  • 10,793
  • 3
  • 32
  • 47