On Tue, Sep 14, 2021 at 11:02 PM Valentin Berlier
I find that when I run into a similar scenario the reason why I need the iterable to be non-empty is because I'm trying to find something in it, and for this the `else` clause works pretty well:
for item in get_items(): if check(item): do_thing(item) break else: raise ValueError()
Early returns can also be useful:
for item in get_items(): if check(item): return do_thing(item) raise ValueError()
Another useful method is a sentinel: item, no_items = object() for item in get_items(): frob(item) if item is no_items: raise ValueError() --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler