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


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

Re: A little morning puzzle

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2012-09-19 09:16 -0600
Last post2012-09-19 09:16 -0600
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#29500 — Re: A little morning puzzle

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-09-19 09:16 -0600
SubjectRe: A little morning puzzle
Message-ID<mailman.921.1348067815.27098.python-list@python.org>
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]

[toc] | [standalone]


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


csiph-web