Hacker News new | ask | show | jobs
by wlesieutre 3666 days 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.

2 comments

That 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.
And 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.