擅长:python、mysql、java
<p>使用有序字典的另一种方法(2.7):</p>
<pre><code>from collections import OrderedDict
a = OrderedDict((var_name,eval(var_name))
for var_name in sorted(['atotal','ainitial','btotal','binitial']))
while True:
try:
init_value = a.popitem(last=False)
total_value = a.popitem(last=False)
if init_value[1] == total_value[1]:
print ("The population of {0} has "
"not changed".format(init_value[0][0].upper()))
except:
break
</code></pre>