Created
June 22, 2019 04:55
-
-
Save eyaltrabelsi/5822f51bb344b09b3d1c9067f801ced5 to your computer and use it in GitHub Desktop.
Python trick For else example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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