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
approach.

On Mon, Apr 22, 2019 at 11:47 PM 林自均 <johnl...@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.
>
> Best,
> John Lin
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to