Help building a dictionary of lists

Thomas Bach thbach at students.uni-mainz.de
Tue Nov 13 08:53:55 EST 2012


On Mon, Nov 12, 2012 at 11:41:59PM +0000, Joshua Landau wrote:
> 
> Dict comprehension:
> {i:[] for i in ["Test 1", "Test 2", "Test 3"]}

In Python 2.6 this syntax is not supported. You can achieve the same
there via

dict((i, []) for i in ['Test 1', 'Test 2', 'Test 3'])

Also have a look at ``collections.defaultdict``.

Regards,
	Thomas.



More information about the Python-list mailing list