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


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

Re: A little morning puzzle

Started byPeter Otten <__peter__@web.de>
First post2012-09-19 13:33 +0200
Last post2012-09-19 13:33 +0200
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 Peter Otten <__peter__@web.de> - 2012-09-19 13:33 +0200

#29480 — Re: A little morning puzzle

FromPeter Otten <__peter__@web.de>
Date2012-09-19 13:33 +0200
SubjectRe: A little morning puzzle
Message-ID<mailman.908.1348054351.27098.python-list@python.org>
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]

[toc] | [standalone]


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


csiph-web