
On 12/27/2019 10:37 AM, Marco Sulla via Python-ideas wrote:
Eric Fahlgren wrote:
You apparently did not read the posts, because the point was whether it raises or returns a default value, not whether it saves one line or ten. You apparently don't know Python:
Please be more respectful.
``` next(iterator) # raises an exception if no more elements next(iterator, _sentinel) # returns _sentinel if no more elements ```
So, what's the advantage of having `first()`?
As discussed, it would raise a different exception. One not involved in the normal looping control mechanism.
Furthermore, **how can you be sure this is the __real first element__ of the iterable, if you pass an iterator?**
The disadvantage is that you hide the iterator, that could be useful later in the code.
You could pass in an iterator, and continue to use it. Many examples have shown this. Eric