passing multiple strings to string.find()

Raymond Hettinger vze4rx4y at
Fri Aug 8 06:27:11 CEST 2003

"hokiegal99" <hokiegal99 at> wrote in message
news:3F331A9B.9020907 at
> How do I say:
> x = string.find(files, 'this', 'that', 'the-other')
> currently I have to write it like this to make it work:
> x = string.find(files, 'this')
> y = string.find(files, 'that')
> z = string.find(files, 'the-other')

Try this:

   x, y, z = map(files.find, ['this', 'that', 'the-other'])

or, if you're just trying to find the first match:'this|that|the-other', files).start()

OTOH, you've hinted at an application that may not
appropriate for multiple string searches.  Instead, look
at building a dictionary or list of files -- they are most
easily searched and better suited for associating other
data such as file sizes, etc.

Raymond Hettinger

More information about the Python-list mailing list