Skip to content

Instantly share code, notes, and snippets.

@CharudattaManwatkar
Last active April 8, 2021 18:17
Show Gist options
  • Save CharudattaManwatkar/c23413d382acb3452d1c1701038f3b4d to your computer and use it in GitHub Desktop.
Save CharudattaManwatkar/c23413d382acb3452d1c1701038f3b4d to your computer and use it in GitHub Desktop.
Alternative to for-else
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