def diffs(*mappings, missing=MISSING):
"""Yield keys and values which differ between the two mappings.
A 'mapping' is any object which implements keys() and __getitem__().
"""
assert mappings
assert all(isinstance(mapping, Mapping) for mapping in mappings)
# Defer to __eq__(), even if it contradicts the algorithm below
if all_eq(mappings):
return
keys = chain.from_iterable(mapping.keys() for mapping in mappings)
for key in unique(keys):
vals = tuple(values(mappings, key))
if not all_eq(vals):
yield key, vals
评论列表
文章目录