Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Why did I think of popping before slicing, lol solution in Creative category for Remove All Before by BootzenKatzen
from collections.abc import Iterable
# This is my solution, which I did without hints for once!
def remove_all_before(items: list, border: int) -> Iterable:
if border in items:
num = (items.index(border))
for i in range(num):
items.pop(0) #pop removes items from a list, so I'm popping until the indexed number
return items
#This is their solution, which I'll admit, is much simpler
def remove_all_before2(items: list, border: int) -> Iterable:
return items[items.index(border):] if border in items else items #it's much simpler to just return [borderindex:] lol
# I don't know why I didn't think of just slicing
print("Example:")
print(list(remove_all_before([1, 2, 3, 4, 5], 3)))
# These "asserts" are used for self-checking
assert list(remove_all_before([1, 2, 3, 4, 5], 3)) == [3, 4, 5]
assert list(remove_all_before([1, 1, 2, 2, 3, 3], 2)) == [2, 2, 3, 3]
assert list(remove_all_before([1, 1, 2, 4, 2, 3, 4], 2)) == [2, 4, 2, 3, 4]
assert list(remove_all_before([1, 1, 5, 6, 7], 2)) == [1, 1, 5, 6, 7]
assert list(remove_all_before([], 0)) == []
assert list(remove_all_before([7, 7, 7, 7, 7, 7, 7, 7, 7], 7)) == [
7,
7,
7,
7,
7,
7,
7,
7,
7,
]
print("The mission is done! Click 'Check Solution' to earn rewards!")
April 3, 2023
Comments: