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 First by Phil15
# Change items IN-PLACE.
def replace_first(items: list) -> list:
if items:
items.append(items.pop(0))
return items
# Slices
def replace_first(items: list) -> list:
return items[1:] + items[:1]
# collections.deque have an useful method: rotate.
from collections import deque
def replace_first(items: list) -> deque:
items = deque(items)
items.rotate(-1)
return items
Jan. 4, 2020
Comments: