4 ms·
I understand that list comprehensions are only for simple list construction. So you don't print or branch. Comment is pretty simple though. My perspective is t
by iofj 11y ago
I understand that list comprehensions are only for simple list construction. So you don't print or branch. Comment is pretty simple though.
My perspective is that in large codebases I have far more trouble remembering function names and what they do than I ever have trouble decoding statements. So the increased code size, long functions and ... that comes from those long list construction statements and loops always seems to take more out of me than difficult list or dictionary comprehensions. Also there are very much fewer places for bugs to hide.
There's also the additional argument that list comprehensions are more efficient because they don't actually construct the list. They generate iterators. It is not a huge difference like in Haskell but it definitely helps.
And there are special cases where you have to use list comprehensions : infinite lists can work as a comprehension, yet the equivalent code to generate them is pages long.