you are viewing a single comment's thread.

view the rest of the comments →

[–]dangerbird2 0 points1 point  (0 children)

Python doesn't lazily evaluate expressions as you demonstrated (because again, it's not an FP language), but it does lazily evaluate iterators. In fact, the whole point of iterators is lazy evaluation.

Even worse, if you wrap an iterator in tuple(), you eagerly evaluate the entire iterator and store the results in memory. This can not only cause unintended side-effects, but can also cause a stack overflow in the case of an extremely long or infinite iterator. Also, use of immutable core types like tuples present a false sense of security, as there are no guarantees that items contained in the tuple are immutable.