3 ms·
I think the first_true optio is great and I highly recommend more-itertools, but if you’re looking for a built in alternative I usually use next((I for I in
by memco 5y ago
I think the first_true optio is great and I highly recommend more-itertools, but if you’re looking for a built in alternative I usually use
next((I for I in iter if is_thing(I)), default)
It’s slightly more work than any but is pretty much all I need when I need to handle whatever values are returned from the any.