Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Dict comprehension help

Reply
Thread Tools

Dict comprehension help

 
 
Joseph L. Casale
Guest
Posts: n/a
 
      12-06-2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Dict comprehension help Joseph L. Casale Python 0 12-06-2012 03:32 PM
RE: Dict comprehension help Peter Otten Python 0 12-06-2012 10:45 AM
RE: Dict comprehension help Joseph L. Casale Python 0 12-06-2012 04:38 AM
Re: Dict comprehension help Ian Kelly Python 0 12-06-2012 03:38 AM
List comprehension in if clause of another list comprehension Vedran Furac( Python 4 12-19-2008 01:35 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57