idfx

replace_first

Sep 13th, 2021 (edited)
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. from typing import Iterable
  2. def replace_first(items: list) -> Iterable:
  3.     """
  4.    In a given list the first element should become the last one.
  5.    An empty list or list with only one element should stay the same.
  6.    """
  7.     item = items.pop(0)
  8.     return items.append(item)
  9.  
  10. print(list(replace_first([1, 2, 3, 4])))
Advertisement
Add Comment
Please, Sign In to add comment