map in Python
Stu
stuart at zapata.org
Fri Jan 21 07:25:27 EST 2005
I have recently switched over to Python from Perl. I want to do
something like this in Python:
@test = ("a1", "a2", "a3");
map {s/[a-z]//g} @test;
print @test;
However, I take it there is no equivalent to $_ in Python. But in that
case how does map pass the elements of a sequence to a function? I
tried the following, but it doesn't work because the interpreter
complains about a missing third argument to re.sub.
import re
test = ["a1", "a2", "a3"]
map(re.sub("[a-z]", ""), test)
print test
Thanks in advance.
Regards,
Stuart <stuart AT zapata DOT org>
More information about the Python-list
mailing list