map in Python
Simon Brunning
simon.brunning at gmail.com
Fri Jan 21 07:42:31 EST 2005
On Fri, 21 Jan 2005 12:37:46 +0000, Simon Brunning
<simon.brunning at gmail.com> 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(lambda item: re.sub("[a-z]", "", item), test)
>>> test
['1', '2', '3']
I much prefer the first list comprehension form myself, but reasonable
men can differ...
--
Cheers,
Simon B,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/
More information about the Python-list
mailing list