Rodrigo Girão Serrão 🐍🚀 @mathspp.com · Dec 11

It's so ANNOYING to break out of nested loops. Auxiliary variables, conditional statements, non-linear paths through your code... It's a mess! But if you extract the looping logic to a generator, you get: - less indentation ✨ - a flat loop you can easily break out of ✨

17 likes 1 replies

?

Replies

Rodrigo Girão Serrão 🐍🚀 · Dec 11

I learned this 1+ year ago from @nedbat.com and had to use it yesterday with the code shown above. I was so annoyed by my code on the left and SUDDENLY I remembered Ned's trick and voilà, my code became so much nicer...