FInd first tuple argument for str.find and str.index
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
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@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@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
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. Cheers, Ron
On 9/4/07, Ron Adam <rrr@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@python.org http://mail.python.org/mailman/listinfo/python-ideas
participants (2)
-
Guido van Rossum
-
Ron Adam