I have the following Python data structures:
data1 = [{'name': u'String 1'}, {'name': u'String 2'}]
data2 = [{'name': u'String 1'}, {'name': u'String 2'}, {'name': u'String 3'}]
I'm looking for the best way to get the delta between the two lists. Is there anything in Python that's as convenient as the JavaScript Underscore.js (_.difference) library?
How about this:
Edit:
If you need symmetric difference you can use :
or
One more edit
You can also use sets:
Use
itertools.filterfalse
:In case you want the difference recursively, I have written a package for python: https://github.com/seperman/deepdiff
Installation
Install from PyPi:
Example usage
Importing
Same object returns empty
Type of an item has changed
Value of an item has changed
Item added and/or removed
String difference
String difference 2
Type change
List difference
List difference 2:
List difference ignoring order or duplicates: (with the same dictionaries as above)
List that contains dictionary:
Sets:
Named Tuples:
Custom objects:
Object attribute added: