Comment Comment by nostoc 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) parent nostoc 1 year ago