Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37638
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <Arah.Leonard@bruker-axs.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.071 |
| X-Spam-Evidence | '*H*': 0.86; '*S*': 0.00; 'subject:help': 0.07; 'dict': 0.09; 'slightly': 0.15; 'keys:': 0.16; 'to:name:python- list@python.org': 0.20; 'keys': 0.22; 'header:In-Reply-To:1': 0.25; 'values': 0.26; 'thanks!': 0.26; "skip:' 10": 0.30; 'print': 0.32; 'anyone': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'list': 0.35; 'problem,': 0.35; 'similar': 0.35; 'but': 0.36; 'received:71': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'received:10': 0.38; 'to:addr:python.org': 0.39; 'build': 0.39; 'different': 0.63; 'insight': 0.71; 'subject:comp': 0.96 |
| From | "Leonard, Arah" <Arah.Leonard@bruker-axs.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Subject | RE: Dict comp help |
| Thread-Topic | Dict comp help |
| Thread-Index | AQHN+nSpzyWBdtr5P0a8ac9F4riuJphY/7ow |
| Date | Thu, 24 Jan 2013 21:39:37 +0000 |
| References | <assp.07360d00b0.753cb595af8449f689dabf8b28611e52@exch.activenetwerx.com> |
| In-Reply-To | <assp.07360d00b0.753cb595af8449f689dabf8b28611e52@exch.activenetwerx.com> |
| Accept-Language | en-US |
| Content-Language | en-US |
| X-MS-Has-Attach | |
| X-MS-TNEF-Correlator | |
| x-originating-ip | [10.73.1.96] |
| Content-Type | text/plain; charset="iso-8859-1" |
| Content-Transfer-Encoding | quoted-printable |
| MIME-Version | 1.0 |
| X-OriginalArrivalTime | 24 Jan 2013 21:39:38.0247 (UTC) FILETIME=[4F547970:01CDFA7B] |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1019.1359063580.2939.python-list@python.org> (permalink) |
| Lines | 32 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1359063580 news.xs4all.nl 6936 [2001:888:2000:d::a6]:36975 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:37638 |
Show key headers only | View raw
> Hi,
> 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?
>
>
> Thanks!
> jlc
>
listy = [{'a':'xx', 'b':'yy', 'c':'zz'}, {'a':'dd', 'b':'ee','c':'ff'}]
kryten = {}
keys = []
for l in listy:
for key in l.keys():
if key not in keys: keys.append(key)
for key in keys:
kryten[key] = ''
for l in listy:
kryten[key] += l.has_key(key) and l[key] or ''
print kryten
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE: Dict comp help "Leonard, Arah" <Arah.Leonard@bruker-axs.com> - 2013-01-24 21:39 +0000
csiph-web