Skip to content

Instantly share code, notes, and snippets.

@eyaltrabelsi
Created June 22, 2019 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyaltrabelsi/5822f51bb344b09b3d1c9067f801ced5 to your computer and use it in GitHub Desktop.
Save eyaltrabelsi/5822f51bb344b09b3d1c9067f801ced5 to your computer and use it in GitHub Desktop.
Python trick For else example
# For example assume that I need to search through a list and process each item until a flag item is found and
# then stop processing. If the flag item is missing then an exception needs to be raised.
for i in mylist:
if i == theflag:
break
process(i)
else:
raise ValueError("List argument missing terminal flag.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment