Skip to content

Home

Drop list elements from the right

Returns a list with n elements removed from the right.

def drop_right(a, n = 1):
  return a[:-n]

drop_right([1, 2, 3]) # [1, 2]
drop_right([1, 2, 3], 2) # [1]
drop_right([1, 2, 3], 42) # []

More like this

Start typing a keyphrase to see matching snippets.