Q:

Python How remove sublist duplicate side by side?

My question is: I have this list:
[['x', '2', 'NOT'], [['sw'], ['y', '1', 'P12'], ['sw']], [['sw'],
['y', '2', 'NOT'], ['sw']], ['x', 'P01'], ['y', 'Xt']]

I'd like to delete the elements duplicate when they appear side by side.
Example:['sw']], [['sw']
The end result should be:
 [['x', '2', 'NOT'], ['sw'], ['y', '1', 'P12'], ['y', '2', 'NOT'], ['sw'], 
 ['x', 'P01'], ['y', 'Xt']]

I have tried a lot, but I can do that.

A:

To remove the duplicate elements,
mylist=[['x', '2', 'NOT'], ['sw'], ['y', '1', 'P12'], ['sw'], ['sw'], ['y', '2', 'NOT'], ['sw'], ['x', 'P01'], ['y', 'Xt']]
print (mylist)

newlist=[]
for i, e in enumerate(mylist):
    try:
        if not (mylist[i-1] == mylist[i] or mylist[i] == mylist[i+1]):
            newlist.append(e)
    except IndexError:
        newlist.append(e)

print (newlist)

Gives the results
[['x', '2', 'NOT'], ['sw'], ['y', '1', 'P12'], ['sw'], ['sw'], ['y', '2', 'NOT'], ['sw'], ['x', 'P01'], ['y', 'Xt']]
[['x', '2', 'NOT'], ['sw'], ['y', '1', 'P12'], ['y', '2', 'NOT'], ['sw'], ['x', 'P01']]

