Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34399
| 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 | <jcasale@activenetwerx.com> |
| 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" <jcasale@activenetwerx.com> |
| To | Python [python-list@python.org] <python-list@python.org> |
| 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> <CALwzidmPjPLJR+GyYsoefCiTdJ4YpfN5Vb+LDXVAWWMWFbRPrA@mail.gmail.com> <k9psu6$2et$1@ger.gmane.org> |
| In-Reply-To | <k9psu6$2et$1@ger.gmane.org> |
| 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 <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.568.1354808075.29569.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
>You could put the loop into a helper function, but if you are looping
>through the same my_list more than once why not build a lookup table
>
>my_dict = {d["key"]: d for d in my_list}
>
>and then find the required dict with
>
>my_dict[value]
I suppose, what I failed to clarify was that for each list of dicts, I may
only extract out one (maybe two) dicts, but I have several to do this for.
The tidy one-liners make for populating the vars in __init__ nice and clean.
Much appreciated guys, thanks!
jlc
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE: Dict comprehension help "Joseph L. Casale" <jcasale@activenetwerx.com> - 2012-12-06 15:32 +0000
csiph-web