Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple solution in Clear category for Replace First by BootzenKatzen
from collections.abc import Iterable
#This is the first time my solution has matched the solution they give in the hints!
def replace_first(items: list) -> Iterable:
if items: #making sure there's something on the list, or it throws an error
items.append(items.pop(0)) #pop removes an item from the list at the indexed point, and returns it
return items #so we're appending the list with the item we popped off the beginning
# which moves the first item to the end of the list
# 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!")
April 3, 2023
Comments: