A little morning puzzle

Peter Otten __peter__ at web.de
Wed Sep 19 07:33:04 EDT 2012


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]





More information about the Python-list mailing list