r/Python • • Dec 19 '22

Intermediate Showcase multi line lambdas, as god intended

4 parallel universes ahead of the linter

codec abuse, part 2. https://github.com/dankeyy/superlambda.py

gl hf hope you like it

53 Upvotes

31 comments sorted by

View all comments

Show parent comment

1

u/dankey26 Dec 31 '22 edited Dec 31 '22

the opposite is true, it'd run if the loop ended naturally (again see the link above).

In [1]: for i in [1,2,3]:
   ...:     print(i)
   ...:     break
   ...: else:
   ...:     print('else')
   ...: 
1

In [2]: for i in []:
   ...:     print(i)
   ...:     break
   ...: else:
   ...:     print('else')
   ...: 
else

In [3]: for i in []:
   ...:     print(i)
   ...: else:
   ...:     print('else')
   ...: 
else

In [4]: for i in [1,2,3]:
   ...:     print(i)
   ...: else:
   ...:     print('else')
   ...: 
1
2
3
else

1

u/iceytomatoes Dec 31 '22

yes, you're correct, i had it mixed up