easier solution possible to find a stringpattern in a list?

christof hoeke csad7 at yahoo.com
Sat Jan 4 17:29:05 CET 2003

thanks, i thought there should be something in the standard modules...

thanks a lot.

"christof hoeke" <csad7 at yahoo.com> wrote in message
news:av6m3r$n5m$01$1 at news.t-online.com...
> 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
> filesystem.
> thanks for any help
> chris

More information about the Python-list mailing list