13

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
  • 849
  • 2
  • 10
  • 19

1 Answers1

35

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
  • 15,740
  • 4
  • 35
  • 52