map() question...

Peter Hansen peter at
Mon Jan 13 03:25:01 CET 2003

Kevin Ethridge wrote:
> Why doesn't map() work with the print function?
> ie map(print, ['Have', 'a', 'great', 'day.'])

Because print is a statement, not a function.  Map must take
a function.  You'd have to do this to get the effect you want,
though there are better ways and this one just plain stinks:

def printit(item):
    print item

map(printit, ['Have','a','reasonably','nice','day.'])

Using the form "print('a string')" is perhaps poor style, since
it suggests print is a method.  Same applies to return, which is
also a statement (as in C, where people also get it wrong).


More information about the Python-list mailing list