4 ms·
It's the other way around, they are not removed, the default implementations are now lazy. So in python 3 you get an interator: >>> map(lambda i:i*i, range(
by maxerickson 12y ago
It's the other way around, they are not removed, the default implementations are now lazy. So in python 3 you get an interator:
>>> map(lambda i:i*i, range(5))
<map object at 0x010622F0>
and have to explicitly construct a list:
>>> list(map(lambda i:i*i, range(5)))
[0, 1, 4, 9, 16]
>>>
- merlincorey 12y agoAh, I actually like that! That is indeed cleaner. Thanks for the explanation.
- agentultra 12y agoTraversing a binary tree without an explicit stack is also much cleaner thanks to sub-generators. if tree.left: yield from traverse(tree.left) yield tree if tree.right: yield from traverse(tree.right) As a trivial example.