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


Groups > comp.lang.python > #29480

Re: A little morning puzzle

From Peter Otten <__peter__@web.de>
Subject Re: A little morning puzzle
Date 2012-09-19 13:33 +0200
Organization None
References <k3c9jb$2gr$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.908.1348054351.27098.python-list@python.org> (permalink)

Show all headers | View raw


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?

>>> items = [
... {1:2, 2:2},
... {1:1, 2:2},
... ]
>>> first = items[0].items()
>>> [key for key, value in first if all(item[key] == value for item in 
items)]
[2]

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


Thread

Re: A little morning puzzle Peter Otten <__peter__@web.de> - 2012-09-19 13:33 +0200

csiph-web