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


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

Dict comprehension help

Started by"Joseph L. Casale" <jcasale@activenetwerx.com>
First post2012-12-06 03:03 +0000
Last post2012-12-06 03:03 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#34354 — Dict comprehension help

From"Joseph L. Casale" <jcasale@activenetwerx.com>
Date2012-12-06 03:03 +0000
SubjectDict comprehension help
Message-ID<mailman.541.1354763128.29569.python-list@python.org>
I get a list of dicts as output from a source I need to then extract various dicts
out of. I can easily extract the dict of choice based on it containing a key with
a certain value using list comp but I was hoping to use dict comp so the output
was not contained within a list.

reduce(lambda x,y: dict(x.items() + y.items()), filter(lambda z: z['key'] == value, my_list))

where my_list is a list of dicts. The premise is all dicts in the list have a unique
value for z['key'].

Anyone have a pointer as to how I might tackle this without lambdas and only
using dict comp?

Thanks!
jlc

[toc] | [standalone]


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


csiph-web