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

Ron Adam rrr at ronadam.com
Thu Sep 6 13:58:40 CEST 2007

Guido van Rossum wrote:
> I was surprised to find that startswith and endswith support this, but
> it does make sense. Adding a patch to 2.6 would cause it to be merged
> into 3.0 soon enough.

I'll give it a try but it may take me a while to do it.  If someone else 
wants to do this and is more familiar with the string and unicode objects 
that would be good.


> On 9/4/07, Ron Adam <rrr at ronadam.com> wrote:
>> 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
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> http://mail.python.org/mailman/listinfo/python-ideas

More information about the Python-ideas mailing list