easier solution possible to find a stringpattern in a list?

christof hoeke csad7 at yahoo.com
Sat Jan 4 08:03:58 EST 2003


hi,
i was wondering if there is an easier solution to the following problem (i
am more or less a beginner in python):

i have a list of filenames and want to know if there is one or more files
with a given pattern in it.
a bit similar to what glob.glob(pattern) is doing.

my solution till now would be

files = [...]
pattern = "*.xsl"
number = len( [f for f in files if f.endswith(pattern)] )
if  number > 0:
    print number + " times in the list"
else:
    print "not in the list"

is there already a function in the standard modules that can do something
like this?
maybe even one which can handle more generalized patterns?
i guess i am looking for a version of glob which handles a list and not the
filesystem.

thanks for any help
chris







More information about the Python-list mailing list