dictionary – python-How to solve KeyError: 2?

dictionary – python-How to solve KeyError: 2?

In order to set a general default value for all keys, you can use defaultdict:

from collections import defaultdict

d = defaultdict(list)    
d[0].append(1)

dictionary – python-How to solve KeyError: 2?

Leave a Reply

Your email address will not be published. Required fields are marked *