Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
One Liner solution in Creative category for Remove All After by Safwan_Samsudeen
from typing import Iterable
def remove_all_after(items: list, border: int) -> Iterable:
return items[:items.index(border) + 1] if border in items else items
def test():
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]
if __name__ == '__main__':
print("Example:")
print(list(remove_all_after([1, 2, 3, 4, 5], 3)))
test()
print("Coding complete? Click 'Check' to earn cool rewards!")
Dec. 2, 2020
Comments: