Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Replace First by arun_maiti
from collections.abc import Iterable
def replace_first(items: list) -> Iterable:
if items:
# The items.pop(0) method stores the value it cut
# that is, the first one from the list, so we can
# immediately insert it into the list
items.append(items.pop(0))
return items
# 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!")
Dec. 4, 2025
Comments: