Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
MySolutionReplaceFirst solution in Clear category for Replace First by jemg2030
from collections.abc import Iterable
def replace_first(items: list) -> Iterable:
# your code here
if len(items) <= 1: # If empty or only 1 element
return items
else:
return items[1:] + [items[0]]
# These "asserts" are used for self-checking
print("Example:")
print(list(replace_first([1, 2, 3, 4])))
assert replace_first([1, 2, 3, 4]) == [2, 3, 4, 1]
assert replace_first([1]) == [1]
assert replace_first([]) == []
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 16, 2023
Comments: