map() question...

Erik Max Francis max at
Mon Jan 13 03:50:29 CET 2003

Mike Meyer wrote:

> "Kevin Ethridge" <kevinethridge at> writes:
> > Why doesn't map() work with the print function?
> > ie map(print, ['Have', 'a', 'great', 'day.'])
> Because print isn't a function, it's a statement. It will work with
> sys.stdout.write.

Only if wrapped in a lambda.  Don't forget that trailing newline that's
implicit in a print statement (one with no trailing comma, anyway):

	lambda x: sys.stdout.write(x + '\n')

 Erik Max Francis / max at /
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ If the sky should fall, hold up your hands.
\__/ (a Spanish proverb)
    Maths reference /
 A mathematics reference.

More information about the Python-list mailing list