Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'function,': 0.07; 'subject:skip:c 10': 0.07; 'subject:help': 0.07; '__init__': 0.09; 'dict': 0.09; 'lookup': 0.09; 'guys,': 0.16; 'looping': 0.16; 'two)': 0.16; 'helper': 0.17; 'header:In-Reply-To:1': 0.25; 'thanks!': 0.26; 'appreciated': 0.27; 'skip:> 10': 0.27; 'received:10.0.0': 0.28; '(maybe': 0.29; 'could': 0.32; 'clarify': 0.33; 'extract': 0.33; 'received:10.0': 0.33; 'to:addr:python- list': 0.33; 'list': 0.35; 'table': 0.35; 'but': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'received:10': 0.38; 'several': 0.39; 'to:addr:python.org': 0.39; 'build': 0.39; 'charset:windows-1256': 0.61; 'received:unknown': 0.63; 'more': 0.63 X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.1 cv=+lz5uX4xiInwtrymCIFxsZpC13k2qgqBCqxhxbRs02Y= c=1 sm=1 a=e0aVyHJSPUcA:10 a=7PYXob_7ZXMA:10 a=BLceEmwcHowA:10 a=eoNxP8pz9j0A:10 a=oNw28mxuUhXRB3mVwYQ4Ag==:17 a=sdR_XE5w16_n_a7v8RcA:9 a=RFXaeJp-pwgA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 From: "Joseph L. Casale" To: =?windows-1256?Q?Python_=FD=5Bpython-list=40python=2Eorg=5D=FD?= Subject: RE: Dict comprehension help Thread-Topic: Dict comprehension help Thread-Index: AQHN057CP4x4OdPOStSEWGN69T+4JpgL5dp0 Date: Thu, 6 Dec 2012 15:32:19 +0000 References: <92097A6A775D5147B1078E3F15430B92349092E6@prato.activenetwerx.local> <92097A6A775D5147B1078E3F15430B92349094F3@prato.activenetwerx.local>, In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.0.0.4] Content-Type: text/plain; charset="windows-1256" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354808075 news.xs4all.nl 6910 [2001:888:2000:d::a6]:35709 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34399 >You could put the loop into a helper function, but if you are looping=0A= >through the same my_list more than once why not build a lookup table=0A= >=0A= >my_dict =3D {d["key"]: d for d in my_list}=0A= >=0A= >and then find the required dict with=0A= >=0A= >my_dict[value]=0A= =0A= I suppose, what I failed to clarify was that for each list of dicts, I may= =0A= only extract out one (maybe two) dicts, but I have several to do this for.= =0A= =0A= The tidy one-liners make for populating the vars in __init__ nice and clean= .=0A= =0A= Much appreciated guys, thanks!=0A= jlc=