Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37636
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Dict comp help |
| Date | 2013-01-24 22:23 +0100 |
| Organization | None |
| References | <assp.07360d00b0.753cb595af8449f689dabf8b28611e52@exch.activenetwerx.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1017.1359062623.2939.python-list@python.org> (permalink) |
Joseph L. Casale wrote:
> Slightly different take on an old problem, I have a list of dicts, I need
> to build one dict from this based on two values from each dict in the
> list. Each of the dicts in the list have similar key names, but values of
> course differ.
>
>
> [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': 'dd', 'b': 'ee', 'c': 'ff'}]
>
>
> { 'xx': 'zz', 'dd': 'ff'}
>
>
> Anyone have insight on how to pull this off?
>>> data = [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': 'dd', 'b': 'ee', 'c':
'ff'}]
>>> {d["a"]: d["c"] for d in data}
{'xx': 'zz', 'dd': 'ff'}
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Dict comp help Peter Otten <__peter__@web.de> - 2013-01-24 22:23 +0100
csiph-web