Files
30-seconds-of-code/python/snippets/tail.md
2023-05-01 22:43:50 +03:00

409 B

title, type, tags, cover, dateModified
title type tags cover dateModified
List tail snippet
list
meteora 2020-11-02T19:28:35+02:00

Returns all elements in a list except for the first one.

  • Use slice notation to return the last element if the list's length is more than 1.
  • Otherwise, return the whole list.
def tail(lst):
  return lst[1:] if len(lst) > 1 else lst
tail([1, 2, 3]) # [2, 3]
tail([1]) # [1]