dict initialization

Robert Kern robert.kern at gmail.com
Tue Dec 22 16:41:23 EST 2009


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

For things like this? No. If you find yourself writing this pattern frequently, 
though, you can wrap it up in a function and call that function to get your 
initialized dicts.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list