Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37638 > unrolled thread
| Started by | "Leonard, Arah" <Arah.Leonard@bruker-axs.com> |
|---|---|
| First post | 2013-01-24 21:39 +0000 |
| Last post | 2013-01-24 21:39 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
RE: Dict comp help "Leonard, Arah" <Arah.Leonard@bruker-axs.com> - 2013-01-24 21:39 +0000
| From | "Leonard, Arah" <Arah.Leonard@bruker-axs.com> |
|---|---|
| Date | 2013-01-24 21:39 +0000 |
| Subject | RE: Dict comp help |
| Message-ID | <mailman.1019.1359063580.2939.python-list@python.org> |
> 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 top | Article view | comp.lang.python
csiph-web