[Python-ideas] FInd first tuple argument for str.find and str.index

Ron Adam rrr at ronadam.com
Wed Sep 5 08:59:42 CEST 2007


Could we add the ability of str.index and str.find to accept a tuple as the 
first argument and return the index of the first item found in it.

This is similar to how str.startswith and str.endswith already works.

  |  startswith(...)
  |      S.startswith(prefix[, start[, end]]) -> bool
  |
  |      Return True if S starts with the specified prefix, False otherwise.
  |      With optional start, test S beginning at that position.
  |      With optional end, stop comparing S at that position.
  |      prefix can also be a tuple of strings to try.


This would speed up cases of filtering and searching when more than one 
item is being searched for.  It would also simplify building iterators that 
filter and yield multiple items in order.


A general google code search seems to show it's a generally useful thing to 
do.

http://www.google.com/codesearch?hl=en&lr=&q=%22findfirst%22+string&btnG=Search


(searching for python specific code doesn't show much because python 
doesn't have a findfirst function of any type.)


Cheers,
    Ron




More information about the Python-ideas mailing list