3 ms·
In Python I went back and forth: I discovered list comprehension and was exited and used them a lot. Then I went to multi level list comp. Then I realise I cou
by dorfsmay 8y ago
In Python I went back and forth:
I discovered list comprehension and was exited and used them a lot. Then I went to multi level list comp. Then I realise I could never debug those so went back to loops for anything needing more than a single level. Finally I discovered Generator Expression which are basically like list comp, but lazy (not evaluated) and since then I break my code in a series of generator expression which I materialise at the end with a single list comprehension. This way I keep my code readable, it's a lot cleaner then a bunch of loops, and I also benefit of Python's special optimisation for list comprehension.
- blt 8y agoI like writing generator loops with the yield statement for more complex processing.
- sizeofchar 8y agoThat’s my style as well, and I followed the same path of yours!