<p>问题:<br/>
给定一个包含大写字母和整数(从0到9)的字符串,编写一个函数,按字母和数字之和的顺序返回字母。你知道吗</p>
<p>我的代码:</p>
<pre><code>import re
class Solution:
def rearrange(self, str):
# Write your code here
if str == "":
return str
sum = 0
letter = []
for i in range(len(str)):
if re.search("([A-Z])", str[i]):
letter.append(str[i])
else:
sum += int(str[i])
letsort = sorted(letter)
letstr = "".join(letsort)
result = letstr + str(sum)
return result
</code></pre>
<p>错误:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
File "/code/Main.py", line 20, in
ans = solution.rearrange(str)
File "/code/Solution.py", line 20, in rearrange
result = letstr + str(sum)
TypeError: 'str' object is not callable
</code></pre>
<p>我不明白原因。你知道吗</p>