Combining lists to dictionary

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

Ben Finney <ben+python at> Wrote in message:
> Denis McMahon <denismfmcmahon at> 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))


More information about the Python-list mailing list