Get the first value with the next()
function:
first = last = next(iterable, defaultvalue)
for last in iterable:
pass
This assumes the iterable is finite.
For an empty iterable, first
and last
are set to defaultvalue
. For an iterable with just one element, first
and last
will both refer to that one element. For any other finite iterable, first
will have the first element, last
the very last.