Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Replace Last by vlad.bezden
"""Replace First.
https://py.checkio.org/en/mission/replace-last/
In a given list the last element should become the first one.
An empty list or list with only one element should stay the same
Input: List.
Output: List.
"""
from typing import List
def replace_last(items: List[int]) -> List[int]:
return items[-1:] + items[:-1]
if __name__ == "__main__":
assert list(replace_last([2, 3, 4, 1])) == [1, 2, 3, 4]
assert list(replace_last([1])) == [1]
assert list(replace_last([])) == []
print("PASSED!!!")
July 19, 2020
Comments: