Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: A little morning puzzle (http://www.velocityreviews.com/forums/t952409-re-a-little-morning-puzzle.html)

Peter Otten 09-19-2012 11:33 AM

Re: A little morning puzzle
 
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]




All times are GMT. The time now is 07:33 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.