Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Example "with" solution in Creative category for Replace Last by U.V
class With():
def __init__(self, arr):
self.arr = arr[:]
def __enter__(self):
return self.arr
def __exit__(self, a, b, c):
if a:
return False
def replace_last(items: list) -> list:
with With(items) as w:
items=w
return items[-1:] + items[:-1]
if __name__ == '__main__':
print("Example:")
print(replace_last([2, 3, 4, 1]))
# These "asserts" are used for self-checking and not for an auto-testing
assert replace_last([2, 3, 4, 1]) == [1, 2, 3, 4]
assert replace_last([1, 2, 3, 4]) == [4, 1, 2, 3]
assert replace_last([1]) == [1]
assert replace_last([]) == []
print("Coding complete? Click 'Check' to earn cool rewards!")
Oct. 24, 2022
Comments: