Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
nostoc
8 months ago
|
parent
|
context
|
favorite
| on:
Advanced Python Features
Instead of catching the `StopIteration` exception, you can simply provide a default case to `next` :
next((c for c in candidates if predicate(c)), default)
zahlman
8 months ago
[–]
Indeed. I was thinking of ways to generalize for the case where a default isn't desired, then decided against introducing that complexity in the example, then forgot that I could re-simplify further.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: