Re: map in Python

2005-01-21 Thread Pierre Barbier de Reuille
You have three ways to do what you want : First wayt is to use lambda. Then, you want to write : >>> map(lambda x: re.sub("[a-z]", "", x), test) Second is to use regular named function : >>> def remove_letters( s ): ... re.sub("[a-z]", "", s) >>> map(remove_letters, test) A third way would be to

Re: map in Python

2005-01-21 Thread Simon Brunning
On Fri, 21 Jan 2005 12:37:46 +, Simon Brunning <[EMAIL PROTECTED]> wrote: > This what you want? > > >>> import re > >>> test = ["a1", "a2", "a3"] > >>> test = [re.sub("[a-z]", "", item) for item in test] > >>> test > ['1', '2', '3'] Or, if you *must* use map, you can do: >>> test = map(lambd

Re: map in Python

2005-01-21 Thread Simon Brunning
On 21 Jan 2005 04:25:27 -0800, Stu <[EMAIL PROTECTED]> wrote: > 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.

map in Python

2005-01-21 Thread Stu
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