你可以使用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}
{k: 0 for k in key_list}
- user2390182dict.fromkeys([1, 2, 3], 0)
的结果将是{1: 0, 2: 0, 3: 0}
。 - Patrick Haugh