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

Guido van Rossum guido at python.org
Wed Sep 5 17:05:43 CEST 2007


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.

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
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list