Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Compare with predecessor - one line code solution in Clear category for Compress List by new_hoschi
from typing import Iterable
def compress(items: list) -> Iterable:
if not items: return []
## start with the first element, then (second part of the list)
## append the next element if it is different from its predecessor
return [items[0]]+[j for index,j in enumerate(items[1:]) if items[index]!=j]
April 10, 2020