finding the list of the matched strings
James Stroud
jstroud at mbi.ucla.edu
Sun Nov 5 08:04:19 EST 2006
jm.suresh at no.spam.gmail.com wrote:
> Hi, I have a list of strings. And I want to find the subset which
> matches a particular regular expression.
>
> import re
> ll = ('a', 'b', 's1', 's2', '3s')
> p = re.compile('^s.*')
> newList = filter(lambda s: p.match(s), ll)
>
> I suppose there should be simple function to do this in re module. Is
> there any?
>
> I searched google, but could not find one, may be for keywords were not
> perfect.
>
> Thanks.
> Suresh
>
I think I'm having some network problems. I'll try again. Also the
previous "attempt" had a typo (perhaps a freudian slip).
",".join(some_list).
By the way, don't name your own objects with the names of built-in
types, such as "list" or "str", etc.
More information about the Python-list
mailing list