Use itertools.groupby()
to group your values:
from itertools import groupby
listOut = []
for value, group in groupby(listIn):
listOut.append(next(group))
for i in group:
listOut.append(i)
break
or, for added efficiency, as a generator:
from itertools import groupby
def reduced(it):
for value, group in groupby(it):
yield next(group)
for i in group:
yield i
break
Demo:
>>> listIn = [1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1]
>>> list(reduced(listIn))
[1, 1, 0, 0, 1, 0, 0, 1]