dict initialization

Irmen de Jong irmen-NOSPAM- at xs4all.nl
Tue Dec 22 16:50:07 EST 2009


On 22-12-2009 22:33, mattia wrote:
> 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?

Maybe you can use:
	dict.fromkeys(xrange(1,51))
but this will initialize all values to None instead of an empty list...

-irmen







More information about the Python-list mailing list