Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Remove All After by Buggerman
from typing import Iterable
from itertools import takewhile
def remove_all_after(items: list, border: int) -> Iterable:
for x in items:
yield x
if x == border: return
if __name__ == '__main__':
print("Example:")
print(list(remove_all_after([1, 2, 3, 4, 5], 3)))
# These "asserts" are used for self-checking and not for an auto-testing
assert list(remove_all_after([1, 2, 3, 4, 5], 3)) == [1, 2, 3]
assert list(remove_all_after([1, 1, 2, 2, 3, 3], 2)) == [1, 1, 2]
assert list(remove_all_after([1, 1, 2, 4, 2, 3, 4], 2)) == [1, 1, 2]
assert list(remove_all_after([1, 1, 5, 6, 7], 2)) == [1, 1, 5, 6, 7]
assert list(remove_all_after([], 0)) == []
assert list(remove_all_after([7, 7, 7, 7, 7, 7, 7, 7, 7], 7)) == [7]
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 22, 2021
Comments: