"mattia" <[email protected]> wrote in message
news:[email protected]...
Is there a function to initialize a dictionary?
Right now I'm using:
d = {x+1:[] for x in range(50)}
Is there any better solution?
Depending on your use case, a defaultdict might suite you:
from collections import defaultdict
D=defaultdict(list)
D[0]
[]
D[49]
[]
If the key doesn't exist, it will be initialized by calling the factory
function provided in the constructor.
-Mark
--
http://mail.python.org/mailman/listinfo/python-list