dictdiffer icon indicating copy to clipboard operation
dictdiffer copied to clipboard

Generate new dict from diff - dict of changes

Open p-baum opened this issue 3 years ago • 1 comments

Maybe I've missed something but I cant see how to generate a diff dict.

I need a dict representation of the changes to simplify database updates. Is this possible?

p-baum avatar Oct 18 '22 13:10 p-baum

diff returns a generator. In your use case it sounds like you need to "instantiate" the diff with list, and if you need a dict, you need to wrap the result explicitly. So something like this?

diff_dict = {"changes": list(diff(a, b))}

mikaelho avatar Oct 19 '22 04:10 mikaelho