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


Groups > comp.lang.python > #29500

Re: A little morning puzzle

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.031
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'skip:[ 20': 0.03; 'sep': 0.09; 'dct': 0.16; 'dictionaries': 0.16; 'keys.': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'keys': 0.22; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'values.': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'received:209.85': 0.35; 'item': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'pardon': 0.84; 'to:name:python': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=M+snlVL2YXhktZuYFWKowMiYq4WULaQRkcBw3IM+9WU=; b=w0yMA+04TLDEgQqpF+CuutoFTvmdTdjyYMzFDWIGE82wyOCVdDl+k3S1Z+ZdNPBUvh CbkIWp/SlLWxDddvqetlaMQ7kqewPsb6XEFD2QlFhQKLKncVetN6mIdsHcijesI1RQBj nYVBSaLB5DNJRnaFghm3G2XNT/Il50Wqo5MyUmIA8euW0tWphG+jVZOSOjjdglXDc7OI unZJnNDvIygdul0DbkiGZ7zCiErupCYxK5wijMP18cxJGfdFIGsJD1bRVTLKe0lsAg2z +Z1cji48va5AoTlDn5kmz0YmYuv4lsacJMwRWX92KyYbZST6850PW94o5cFM2mPenXqK 34fA==
MIME-Version 1.0
In-Reply-To <5059B6DD.8030100@rece.vub.ac.be>
References <k3c9jb$2gr$1@ger.gmane.org> <5059B6DD.8030100@rece.vub.ac.be>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 19 Sep 2012 09:16:23 -0600
Subject Re: A little morning puzzle
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.921.1348067815.27098.python-list@python.org> (permalink)
Lines 13
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348067815 news.xs4all.nl 6927 [2001:888:2000:d::a6]:57437
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:29500

Show key headers only | 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