UniCoreFW

head()

Returns the first element of the array, if it exists.

Implementation

Args: array: List from which to retrieve the first element. Returns: The first element of the list if it is not empty, otherwise None.

Example

head([1, 2, 3])

Expected output: 1

Alternative usage:

head([])

Expected output: None

Source Code

def head(array: List[T]) -> Optional[T]: return array[0] if array else None