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: 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" To: "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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 > 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 cours= e differ. >=20 >=20 > [{'a': 'xx',=A0'b': 'yy',=A0'c': 'zz'}, =A0{'a': 'dd',=A0'b': 'ee',=A0'c'= : 'ff'}] >=20 >=20 > { 'xx': 'zz', 'dd': 'ff'} >=20 >=20 > Anyone have insight on how to pull this off? >=20 >=20 > Thanks! > jlc >=20 listy =3D [{'a':'xx', 'b':'yy', 'c':'zz'}, {'a':'dd', 'b':'ee','c':'ff'}] kryten =3D {} keys =3D [] for l in listy: for key in l.keys(): if key not in keys: keys.append(key) for key in keys: kryten[key] =3D '' for l in listy: kryten[key] +=3D l.has_key(key) and l[key] or '' print kryten