one

iteration_utilities.one(iterable, /)

Return the first value in the iterable and expects it only contains one element.

Parameters:

iterable : iterable

The iterable from which to get the one item.

Returns:

one : any type

The first value.

Raises:

ValueError :

If the iterable contains no items or more than one item.

Examples

Some basic examples:

>>> from iteration_utilities import one
>>> one([0])
0
>>> one('b')
'b'

Warning

one() will access the first two values of the iterable so it shoul only be used if the iterable must only contain one item!