Lisp's "some" in Python?

Posted by Mark Probst on Stack Overflow See other posts from Stack Overflow or by Mark Probst
Published on 2010-04-29T15:56:02Z Indexed on 2010/04/29 15:57 UTC
Read the original article Hit count: 265

Filed under:
|

I have a list of strings and a list of filters (which are also strings, to be interpreted as regular expressions). I want a list of all the elements in my string list that are accepted by at least one of the filters. Ideally, I'd write

[s for s in strings if some (lambda f: re.match (f, s), filters)]

where some is defined as

def some (pred, list):
    for x in list:
        res = pred (x)
        if res:
            return res
    return False

Is something like that already available in Python, or is there a more idiomatic way to do this?

© Stack Overflow or respective owner

Related posts about python

Related posts about lisp