You can use itertools.groupby
and grab the first item out of each group using next
.
>>> import itertools
>>> l = [('N',''),('N',''),('K','asdf'),('K','asw'),('S','aqq'),('N',''),('N',''),('N','')]
>>> [next(group) for key, group in itertools.groupby(l)]
[('N', ''), ('K', 'asdf'), ('K', 'asw'), ('S', 'aqq'), ('N', '')]
Edit:
If you just want to remove the consecutive duplicates of the tuples starting with 'N'
then you can use
>>> [key if key[0] == 'N' else list(itertools.chain.from_iterable(group)) for key, group in itertools.groupby(l)]
[('N', ''), ['K', 'asdf'], ['K', 'asw'], ['S', 'aqq'], ('N', '')]