Building a dictionary from a tuple of variable length

Jussi Salmela tiedon_jano at hotmail.com
Mon Mar 5 13:39:54 CET 2007


bg_ie at yahoo.com kirjoitti:
> Hi,
> 
> I have the following tuple -
> 
> t = ("one","two")
> 
> And I can build a dictionary from it as follows -
> 
> d = dict(zip(t,(False,False)))
> 
> But what if my tuple was -
> 
> t = ("one","two","three")
> 
> then I'd have to use -
> 
> d = dict(zip(t,(False,False,False)))
> 
> Therefore, how do I build the tuple of Falses to reflect the length of
> my t tuple?
> 
> Thanks for your help,
> 
> Barry.
> 

Another variation:

d = dict((x, False) for x in t)

Cheers,
Jussi



More information about the Python-list mailing list