I have a nested list:
l = [['GILTI', 'was', 'intended', 'to','to', 'stifle', 'multinationals'. 'was'],
['like' ,'technology', 'and', 'and','pharmaceutical', 'companies', 'like']]
How can I detect two consecutive elements and delete one without using set or another similar operation? This should be the desired output:
l = [['GILTI', 'was', 'intended','to', 'stifle', 'multinationals'. 'was'],
['like' ,'technology', 'and','pharmaceutical', 'companies', 'like']]
I tried using itertools groupby like this:
from itertools import groupby
[i[0] for i in groupby(l)]
And also, an ordered dict:
from collections import OrderedDict
temp_lis = []
for x in l:
temp_lis.append(list(OrderedDict.fromkeys(x)))
temp_lis
out:
[['GILTI', 'was', 'intended', 'to', 'stifle', 'multinationals'],
['like', 'technology', 'and', 'pharmaceutical', 'companies']]
The second solution might look that works well. However,it is wrong because it is deleting non consecutive repeated elements (eg was and like). How can I get the above desired output?