Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34399 > unrolled thread

RE: Dict comprehension help

Started by"Joseph L. Casale" <jcasale@activenetwerx.com>
First post2012-12-06 15:32 +0000
Last post2012-12-06 15:32 +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.


Contents

  RE: Dict comprehension help "Joseph L. Casale" <jcasale@activenetwerx.com> - 2012-12-06 15:32 +0000

#34399 — RE: Dict comprehension help

From"Joseph L. Casale" <jcasale@activenetwerx.com>
Date2012-12-06 15:32 +0000
SubjectRE: Dict comprehension help
Message-ID<mailman.568.1354808075.29569.python-list@python.org>
>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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web