Python - Checking whether any of multiple conditions are true
Question: I am trying to modify a list in place to remove entries where the file
extension does not match. I got this working by writing multiple 'or'
conditions

    
    
    from os import listdir
    image_extensions = ['jpg','.png']
    
    files = listdir('/home')
    files = [x for x in files if '.jpg' in x or '.png' in x]
    
    print files
    

I would like to have this use the image_extensions variable so that I can
easily add more conditions. The latest thing I tried fails with the "requires
string as left operand, not list":

    
    
    from os import listdir
    image_extensions = ['jpg','.png']
    
    files = listdir('/home')
    files = [x for x in files if any(s for s in image_extensions in x)]
    
    print files
    


Answer: This should do:

    
    
    files = [x for x in files if any(s in x for s in image_extensions)]
    #                                |<-->|
    

Check if _any_ of the extensions is contained in the file name `x`

