Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using append and del solution in Creative category for Replace First by H0r4c3
from typing import Iterable
def replace_first(items: list) -> Iterable:
# your code here
if items == []:
return []
if len(items) == 1:
return items
items.append(items[0])
del items[0]
return items
if __name__ == "__main__":
print("Example:")
print(list(replace_first([1, 2, 3, 4])))
# These "asserts" are used for self-checking and not for an auto-testing
assert list(replace_first([1, 2, 3, 4])) == [2, 3, 4, 1]
assert list(replace_first([1])) == [1]
assert list(replace_first([])) == []
print("Coding complete? Click 'Check' to earn cool rewards!")
April 24, 2022