Hacker News new | ask | show | jobs
by BWStearns 3727 days ago
100% agree that lambdas fight python's aesthetics. On the expression complexity front I can definitely say it's easy to slowly increase their complexity until they're no longer readable. As a side note, comprehensions in Python (2 at least, not sure about 3) leak scope a bit which can lead to some really funky bugs if you're in a loop and absentmindedly use a loop variable in a comprehension.

  >> x = 5
  >> [x for x in range(10)]
  >> x # => 9
1 comments

Yes, that was a pain. Particularly because it was only true of list comprehensions, not dict comprehensions or generators:

    Python 2.7.10 ...
    >>> a = 3
    >>> [a for a in range(10)]
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    >>> a
    9
    >>> a = 3
    >>> list(a for a in range(10))
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    >>> a
    3
Guido called it Python's 'dirty little secret'. It is fixed in Py3 though.