Dict comprehension help

  • Thread starter Joseph L. Casale
  • Start date
J

Joseph L. Casale

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 havea 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top