3 ms·
Your suggestion contains bugs, though. To make it fully equivalent to the code in the blog post, it would need to be: sentinel = object() item = next((item
by gvx 8y ago
Your suggestion contains bugs, though. To make it fully equivalent to the code in the blog post, it would need to be:
sentinel = object()
item = next((item for item in container if search_something(item)), sentinel)
if item is not sentinel:
process(item)
else:
not_found_in_container()
... because item could be None or another falsy value.