passing multiple strings to string.find()

Peter Abel p-abel at t-online.de
Fri Aug 8 18:05:05 CEST 2003


hokiegal99 <hokiegal99 at vt.edu> wrote in message news:<3F331A9B.9020907 at vt.edu>...
> 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')

If your problem is to know, if files
in flist and if yes to get the index of the
first occurence then the following could help:
>>> files='that'
>>> flist=['this', 'that', 'the-other'] 
>>> (files in flist and [flist.index(files)] or [None])[0]
1

Regards
Peter




More information about the Python-list mailing list