3 ms·
Similarly, there are people who will insist that the most "pythonic" solution to any problem is list comprehensions nested 3 levels deep. It's OK to wonder "Ca
by wlesieutre 10y ago
Similarly, there are people who will insist that the most "pythonic" solution to any problem is list comprehensions nested 3 levels deep.
It's OK to wonder "Can I do this one one line?" as long as you can step back and say "Yes but I'm not going to" sometimes.
- m_mueller 10y agoThat was one thing I really liked about the Google Python guideline posted here a few days ago: Their rule about list comprehensions. "three lines max, one for the element, one for the list generation and one for the filter clause - no nesting". That's the sweet spot.
- icebraining 10y agoAnd they're just wrong; that goes directly against the Zen of Python: Simple is better than complex. Flat is better than nested. Sparse is better than dense. Readability counts. I too have a tendency to overuse list comprehensions over regular loops, but when they start nesting I know it's almost always time to break it up.