4 ms·
'Lazy lists' are called generators in Python. Just use (...) Instead of [...] in your example.
by whyever 13y ago
'Lazy lists' are called generators in Python. Just use (...) Instead of [...] in your example.
- mercurial 13y agoI'm aware of generator expressions, but the fact that list comprehensions are not lazy can trip people if they are used to other languages with this feature, since they are usually lazy.
- hnriot 13y agoI don't agree, people are more likely to come from python that to python from a language that has lazy list comprehensions. But regardless, using a language requires that you learn it and I doubt many people think list comp is lazy. Pythonic programming obeys explicit over implicit, which which if you want a lazy version you explicitly use a lazy version.
- mercurial 13y ago> Pythonic programming obeys explicit over implicit, which which if you want a lazy version you explicitly use a lazy version. What does this have to do with anything? If the construct was defined as lazy, then it would be just as explicit. There is nothing about generator expressions that says "here, here, this is lazy".
- zodiac 13y agoReading through http://en.wikipedia.org/wiki/List_comprehension http://en.wikipedia.org/wiki/List_comprehension, it seems that there are roughly equal numbers of languages where "list comprehension" produces strict list as languages where it produces lazy lists. I think it's a lack of naming convention - the word "list" on its own means "strict list" in some languages and "lazy list" in others.
- mercurial 13y agoFair enough, I retract my statement :) Maybe people are not surprised after all.