擅长:python、mysql、java
<p>您应该使用字典来存储变量</p>
<p>以下是您的代码-简化:</p>
<pre><code>from operator import itemgetter
def highest_area(self):
directions = dict(
southeast = 0
southwest = 0
northeast = 0
northwest = 0
)
others = 0
for i in self.patient_region:
if i in directions:
directions[i] += 1
else:
others += 1
directions['others'] = others
# highest_dir has the key, while highest_val has the corresponding value
highest_dir, highest_val = max(directions.items(), key=itemgetter(1))
return highest_dir
</code></pre>