Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Pop items solution in Clear category for Compress List by Striga
from typing import Iterable
def compress(items: list) -> Iterable:
i = len(items)-1
while i > 0:
if items[i] == items[i-1]: items.pop(i)
i -= 1
return items
if __name__ == '__main__':
assert list(compress([
5, 5, 5,
4, 5, 6,
6, 5, 5,
7, 8, 0,
0])) == [5, 4, 5, 6, 5, 7, 8, 0]
assert list(compress([1, 1, 1, 1, 2, 2, 2, 1, 1, 1])) == [1, 2, 1]
assert list(compress([7, 7])) == [7]
assert list(compress([])) == []
assert list(compress([1, 2, 3, 4])) == [1, 2, 3, 4]
assert list(compress([9, 9, 9, 9, 9, 9, 9])) == [9]
Nov. 23, 2020
Comments: