<div dir="ltr"><div>Given "abcdefabcdefabcdef", what is the last result of "abc"? x.rindex("abc") will tell you.<br></div><div><br></div><div>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]).<br></div><div><br></div><div>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.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 22, 2019 at 11:47 PM 林自均 <<a href="mailto:johnlinp@gmail.com">johnlinp@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi all,<div><br></div><div>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 <a href="https://bugs.python.org/issue36639" target="_blank">https://bugs.python.org/issue36639</a> to provide list.rindex(). However, the issue was rejected and closed with the comment:</div><div><br></div><div>> 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.</div><div><br></div><div>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.</div><div><br></div><div>Best,</div><div>John Lin</div></div></div></div></div></div>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div>