by merlincorey · 11y ago · 0 comments
>>> 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]
>>>That is indeed cleaner. Thanks for the explanation.
if tree.left:
yield from traverse(tree.left)
yield tree
if tree.right:
yield from traverse(tree.right)
As a trivial example.Same applies to map, filter and I believe reduce as well.