I'm interested in functional programming with python and am working through Mary Rose Cook's blog post A practical introduction to functional programming.
Apparently, it was written in python 2 as this:
name_lengths = map(len, ["Mary", "Isla", "Sam"])
print name_lengths
# => [4, 4, 3]
in Python 3 yields this:
<map object at 0x100b87a20>
I have two questions:
As documented, in the migration guide,
In Python 2 map() returns a list while in Python 3 it returns an iterator.
Python 2:
Apply function to every item of iterable and return a list of the results.
Python 3:
Return an iterator that applies function to every item of iterable, yielding the results.
Python 2 always does the equivalent of list(imap(...))
, Python 3 allows for lazy evaluation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With