问题 Given the following piece of python code: for root, dirs, files in os.walk(directory): for filename in fnmatch.filter(files, '*.png'): pass How can I filter for more than one extension? In this special case I want to get all files ending with *.png, *.gif, *.jpg or *.jpeg. For now I came up with for root, dirs, files in os.walk(directory): for extension in ['jpg', 'jpeg', 'gif', 'png']: for filename in fnmatch.filter(files, '*.' + extension): pass But I think it is not very elegant and