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() _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/7PJDRJ6ESY5KT4VECU57P4PEPPOH4LK5/ Code of Conduct: http://python.org/psf/codeofconduct/