Last active
April 8, 2021 18:17
-
-
Save CharudattaManwatkar/c23413d382acb3452d1c1701038f3b4d to your computer and use it in GitHub Desktop.
Alternative to for-else
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
my_list = ['some', 'list', 'containing', 'five', 'elements'] | |
min_len = 3 | |
no_break = True | |
for element in my_list: | |
if len(element) < min_len: | |
print(f'Caught an element shorter than {min_len} letters') | |
no_break = False | |
break | |
if no_break: | |
print(f'All elements at least {min_len} letters long') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment