using lambda to print everything in a list

Jeff Shipman shippy at nmt.edu
Thu Apr 26 20:26:17 EDT 2001


I've started to discover the real handiness with
lambda expressions in python. I would like to
print out each string in a list without having
a for loop and I thought this was the perfect
candidate for lambda. This is what I'm doing:

map(lambda x: print x, ['line one', 'line two'])

and I get the following error:

  File "<stdin>", line 1
    map(lambda x: print x, ['line one', 'line two'])
                      ^
SyntaxError: invalid syntax

I can do it fine with things like string.replace, but
for some reason does it not like built-in functions?
Is there a way to do what I'm wanting to do? Or must
I use a for loop?

Thanks in advance,
 
Jeff "Shippy" Shipman     E-Mail: shippy at nmt.edu
Computer Science Major    ICQ: 1786493
New Mexico Institute of Mining and Technology
Homepage: http://www.nmt.edu/~shippy



More information about the Python-list mailing list