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
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/JG32LK6LYQ4YG7JAKX7VIGGH5SUJBAGF/
Code of Conduct: http://python.org/psf/codeofconduct/