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


Groups > comp.lang.python > #29500

Re: A little morning puzzle

References <k3c9jb$2gr$1@ger.gmane.org> <5059B6DD.8030100@rece.vub.ac.be>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-09-19 09:16 -0600
Subject Re: A little morning puzzle
Newsgroups comp.lang.python
Message-ID <mailman.921.1348067815.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Sep 19, 2012 at 6:13 AM, Antoon Pardon
<antoon.pardon@rece.vub.ac.be> 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]

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: A little morning puzzle Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-19 09:16 -0600

csiph-web