Re: Combinate 2 lists to a dict ?

vbr at email.cz vbr at email.cz
Wed Apr 18 11:14:55 EDT 2007


> Hi all.
> 
>  I have 2 lists,
>  a = [1,2,3]
>  b = ["ooo","aaa","ppp"]
> 
>  What is the fastest way to make a dict like {1:"ooo",2:"aaa",
> 3:"ppp"} ?
> 
> Thanx

>>> dict(zip(a,b))
{1: 'ooo', 2: 'aaa', 3: 'ppp'}

works for me, but not sure, if it is the fastest way; a, b have to be of the same length, otherwise the shorter is used.

vbr



More information about the Python-list mailing list