Menu

gitpiper

tail python Code Snippet in 2024

listbeginner

Last Updated: 12 April 2024

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]

python snippet similar to tail For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️