Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: A little morning puzzle

Reply
Thread Tools

Re: A little morning puzzle

 
 
Ian Kelly
Guest
Posts: n/a
 
      09-19-2012
On Wed, Sep 19, 2012 at 6:13 AM, Antoon Pardon
<> wrote:
> On 19-09-12 13:17, Neal Becker wrote:
>> I have a list of dictionaries. They all have the same keys. I want to find the
>> set of keys where all the dictionaries have the same values. Suggestions?

> common_items = reduce(opereator.__and__, [set(dct.iteritems()) for dct
> in lst])
> common_keys = set([item[0] for item in common_items])


You can use dictviews for that:

common_items = reduce(operator.__and__, (d.viewitems() for d in ds))
common_keys = [item[0] for item in common_items]
 
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: A little morning puzzle Peter Otten Python 9 09-27-2012 05:58 PM
A little morning puzzle Neal Becker Python 2 09-19-2012 05:12 PM
Re: A little morning puzzle Antoon Pardon Python 0 09-19-2012 12:13 PM
Re: A little morning puzzle Dwight Hutto Python 0 09-19-2012 12:01 PM
Re: A little morning puzzle Peter Otten Python 0 09-19-2012 11:33 AM



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