I am new to python. I have a few questions coming from an armature!
Chris Angelico
rosuav at gmail.com
Tue Aug 16 04:12:08 EDT 2016
On Tue, Aug 16, 2016 at 5:18 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> Also, unless the mapped function is already defined (and preferably
> built-in), a generator expression or list comprehension is usually more
> readable and avoids the significant overhead of repeatedly calling a Python
> function.
Don't know why "built-in" is significant, but most of the point of
map() is to make use of an existing function:
# Instead of
lengths = (len(x) for x in items)
# Use
lengths = map(len, items)
One problem: Not all languages have map() defined the same way.
Built-in function or method? If function, what order are the arguments
in? If method, is it a method on a function or an array/list? If you
add extra arguments, are they treated as parallel arrays, or are they
static arguments to the function - or are they not allowed at all?
Actually, I've never seen map as a function method (which would be
used as "len.map(items)"). All the others, I've seen in various
different languages. Can anyone fill in the gap?
ChrisA
More information about the Python-list
mailing list