List comprehensions and glob

Peter Otten __peter__ at web.de
Thu Jul 15 04:58:23 EDT 2004


Duncan Booth wrote:

> If you want a list comprehension then how about:
> 
> filenames = [ name for pat in PATTERNS for name in glob.glob(pat) ]

>>> PATTERNS = ["*t", "*xt"]
>>> filenames = [name for pat in PATTERNS for name in glob.glob(pat)]
>>> len(filenames), len(sets.Set(filenames))
(66, 39)

Names that match more than one pattern will appear more than once in the
list.

Peter




More information about the Python-list mailing list