Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Three solutions + 1 in comments solution in Clear category for Replace Last by Phil15
# Change items IN-PLACE.
def replace_last(items: list) -> list:
if items:
items.insert(0, items.pop())
return items
# Slices
def replace_last(items: list) -> list:
return items[-1:] + items[:-1]
# collections.deque have an useful method: rotate.
from collections import deque
def replace_last(items: list) -> deque:
items = deque(items)
items.rotate(1)
return items
Jan. 11, 2020
Comments: