shift()
Remove the first element of the array and return it.
Implementation
Args: array: The list to shift. Returns: The first element of the array if it is not empty, otherwise None.
Example
array = [1, 2, 3]
item = shift(array)
item
Expected output: 1
Alternative usage:
array
Expected output: [2, 3]
Source Code
def shift(array: List[T]) -> Optional[T]:
if array:
return array.pop(0)
return None