map() question...
Peter Hansen
peter at engcorp.com
Sun Jan 12 21:25:01 EST 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).
-Peter
More information about the Python-list
mailing list