Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80591

Re: Combining lists to dictionary

From Dave Angel <davea@davea.name>
Subject Re: Combining lists to dictionary
Date 2014-11-12 01:13 -0500
Organization news.gmane.org
References <m3tscl$f1e$2@dont-email.me> <85tx255ib8.fsf@benfinney.id.au>
Newsgroups comp.lang.python
Message-ID <mailman.15714.1415772907.18130.python-list@python.org> (permalink)

Show all headers | View raw


Ben Finney <ben+python@benfinney.id.au> Wrote in message:
> Denis McMahon <denismfmcmahon@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

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Combining lists to dictionary Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-11 20:43 +0000
  Re: Combining lists to dictionary Gary Herron <gherron@digipen.edu> - 2014-11-11 12:55 -0800
  Re: Combining lists to dictionary Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-11-11 13:42 -0800
  Re: Combining lists to dictionary Roy Smith <roy@panix.com> - 2014-11-11 20:06 -0500
  Re: Combining lists to dictionary Ben Finney <ben+python@benfinney.id.au> - 2014-11-12 12:16 +1100
  Re: Combining lists to dictionary Dave Angel <davea@davea.name> - 2014-11-12 01:13 -0500

csiph-web