Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Replace Last by alealan
from collections import deque
def replace_last(items: list):
if len(items) != 0:
item = deque(items[:len(items) - 1])
item.appendleft(items[-1])
else:
item = []
return item
if __name__ == '__main__':
print("Example:")
print(list(replace_last([2, 3, 4, 1])))
# These "asserts" are used for self-checking and not for an auto-testing
assert list(replace_last([2, 3, 4, 1])) == [1, 2, 3, 4]
assert list(replace_last([1])) == [1]
assert list(replace_last([])) == []
print("Coding complete? Click 'Check' to earn cool rewards!")
Aug. 6, 2020