Dictdiffer: Diff and Patch Python dictionaries
1–10 of 11 posts
Re: Dictdiffer: Diff and Patch Python dictionaries
#2I have written at least two dict differs, and I suspect they are like web frameworks - everyone has written a half working one.
However we need good tools that get polished and standardised - this looks nice and I like the full circle ability, but in python's own version of Catch-22, until it succeeds I will stick with writing my own.
I hope it succeeds - my meware sucks
Re: Dictdiffer: Diff and Patch Python dictionaries
#3Re: Dictdiffer: Diff and Patch Python dictionaries
#4What might be some of the use cases?
Re: Dictdiffer: Diff and Patch Python dictionaries
#5Re: Dictdiffer: Diff and Patch Python dictionaries
#6See Guido's "dictionary views" described at: http://www.python.org/dev/peps/pep-3106/ In Python 2.7, those dictionary views are exposed as d.viewkeys(), d.viewitems(), and d.viewvalues(). The key and item views both support set operations such as union, intersection, and difference. Also note, the dict() constructor will accept sequences of items as input. Those tool make it trivially easy to express diffing and patching in native Python:
# diff from d to e
patch = (d.viewitems() - e.viewitems(), # deletions
e.viewitems() - d.viewitems()) # additions
# apply the patch to f
# dict(f.viewitems() - patch[0] | patch[1])Re: Dictdiffer: Diff and Patch Python dictionaries
#7Re: Dictdiffer: Diff and Patch Python dictionaries
#8Some of these capabilities are already built into Python. See Guido's "dictionary views" described at: http://www.python.org/dev/peps/pep-3106/ In Python 2.7, those dictionary views are exposed as d.viewkeys(), d.viewitems(), and d.viewvalues(). The key and item views both support set operations such as union, intersection, and difference. Also note, the dict() constructor will accept sequences of items as input. Tho…
I haven't looked, but I guess it is also recursive on values that are dictionaries themselves. In this case the "patch" is a sort of sequence of edit operations on the dictionary tree.
Re: Dictdiffer: Diff and Patch Python dictionaries
#9I'm getting ambitious now, but what about tree-edit distance (with patch script) for members which are nested lists?
There is Python code out there for these:
https://github.com/timtadh/zhang-shasha
https://code.google.com/p/py-editdist
EDIT I have only used the above libraries for distances, not for patchable diffs. But the Levenshtein and tree-edit distance algorithms are amenable to outputting the patch scripts.
Re: Dictdiffer: Diff and Patch Python dictionaries
#10What might be some of the use cases?