Unifying python dicts? -
does anone have fair algorithm unifying (almost) arbitrary dicts? is, given dicts
a = {1: 1, 2: 2, 3: [1,2,3]} b = {4: 4, 3: [5], 5: {'a': 0, 'b': {}} c = {3: [{'a': '0'}], 5: {'b': {'b': 1}}} unify (a, b, c)
yields
{1: 1, 2: 2, 3: [1, 2, 3, 5, {'a': '0'}], 4: 4, 5: {'a': 0, 'b': {'b': 1}} }
i keep wanting generic solution. wind searching generic solution couple of times year , not finding 1 (no google, unify unification , unify union not same word!), , keep putting off writing 1 myself. know programming prolog leads odd pespective on life, hey, how can 1 have recursive dict/key/value-store , not have unification?
i have in past needed ordering, hence lists, , wound not going generic version hardcoding. time around don't need unification of sets/lists @ all, , fall once again hardcode know keys can ahead of time. but: if there generic solution out there, wouldn't have reinvent wheel again , again. it's wrong have that.
the pythonic solution start __unify__
-method on things can unified, it's basic.
if stuck how iterate through dictionary, using loop iterates through keys:
>>> in {1: "abc"}: print 1
as comments say, please specify problems you're facing rather asking write code you.
Comments
Post a Comment