I have a list of items.. An orginal list and a modified list – what i want to know is which elements have been removed/added from the modified list and what position w.r.t to the original list. The lists do not have duplicates and are not sorted because the ordering of the items in the list matters. Take an example
Org = ['AMEND', 'ASTRT', 'ETIME', 'OBJ', 'ast', 'bias', 'chip', 'cold']
mod = ['AMEND', 'ASTRT', 'OBJ', 'ast', 'bias', 'chip', 'cold', 'flat', 'deb']
in the mod_list ‘ETIME’, was removed and ‘flat’, deb’ were added – so the result of this would be ‘ETIME’ removed at index 2 and ‘flat’, deb’ added at index 8 & 9.
My other problem is detecting if items have changed position. In the example below ‘OBJ’, and ‘ASTRT’ have changed positions.
Org = ['AMEND', 'ASTRT', 'ETIME', 'OBJ', 'ast', 'bias', 'chip', 'cold']
mod = ['AMEND', 'OBJ', 'ETIME', 'ASTRT', 'ast', 'bias', 'chip', 'cold']
Any ideas on how to solve this!
You can use difflib to do this kind of thing:
From here you can iterate through the list and check if items are new or moved or missing. For example: