I need to generate the diff between two arrays of strings:
a=['1','2']
b=['1','2','3']
To achieve this I’m using the difflib library in Python (2.6):
c=difflib.unified_diff(a,b)
and I save the content of
d=list(c)
which is something like:
['--- \n', '+++ \n', '@@ -1,2 +1,3 @@\n', ' 1', ' 2', '+3']
How can I build the second array from the first using the output of the unified_diff function?
The behavior that I’m looking for is something like:
>>> merge(a,d)
>>> ['1','2','3']
P.S. the array can have duplicate entries and the order in which each entry appears is important for my application. Moreover, from one iteration to another there could be changes both in the middle/begin of the array, as well as new entries added at the end.
Not sure that my sample is a good style, but you can use something like this:
OR if your lists could have only unique items:
OR:
OR:
The last one(hope i understand you correctly(sorry if not so) now):