[Python-ideas] What are the strong use cases for str.rindex()?
brett at python.org
Tue Apr 23 13:28:29 EDT 2019
Given "abcdefabcdefabcdef", what is the last result of "abc"?
x.rindex("abc") will tell you.
Given [1, 2, 3, 4, 5, 1, 2, 3, 4, 5] where is the last result of 3?
reversed(x).index(3) will tell you (or x[::-1]).
Notice how with lists you can easily reverse them and still get at the
value since you are searching per index. But with strings, you searching by
a subslice that can be greater than 1 in which case you can't use a similar
On Mon, Apr 22, 2019 at 11:47 PM 林自均 <johnlinp at gmail.com> wrote:
> Hi all,
> I found that there are str.index() and str.rindex(), but there is only
> list.index() and no list.rindex(). So I filed the issue
> https://bugs.python.org/issue36639 to provide list.rindex(). However, the
> issue was rejected and closed with the comment:
> > There were known, strong use cases for str.rindex(). The list.rindex()
> method was intentionally omitted. AFAICT no compelling use cases have
> arisen, so we should continue to leave it out. In general, we don't grow
> the core APIs unnecessarily.
> However, I am not sure what the known, strong use cases for str.rindex()
> are. Why doesn't the strong use cases apply on list.rindex()? Could anyone
> give me some examples? Thanks.
> John Lin
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas