Combining lists to dictionary

Dave Angel davea at davea.name
Wed Nov 12 07:13:33 CET 2014


Ben Finney <ben+python at benfinney.id.au> Wrote in message:
> Denis McMahon <denismfmcmahon at gmail.com> writes:
> 
>> Hi
>>
>> Given x,y are a lists of keys and value that I wish to combine to a 
>> dictionary, such that x[n] is the key for value y[n], which is preferred:
>>
>> z = {a:b for (a,b) in zip(x,y)}
> 
> This one, with the caveat to use PEP-8 compatible formatting::
> 
>     z = {a: b for (a, b) in zip(x, y)}

Or just z = dict(zip (x, y))
> 



-- 
DaveA




More information about the Python-list mailing list