擅长:python、mysql、java
<p>您正在迭代<code>*/+-</code>,因此找到的第一个字符就是返回的第一个字符。你知道吗</p>
<p>您基本上需要找到所有这些操作符的索引,然后找到最大或最小的。尝试重新编写此函数以适用于字符串的另一端:</p>
<pre><code>def find_operator_right(text):
position = -1
for oper in '*/+-':
index = text.rfind(oper)
if index > position:
position = index
return position
</code></pre>
<p>一个稍微更具脓性的解决方案是这样的:</p>
<pre><code>right_index = max(map(text.rfind, '+-/*'))
</code></pre>