擅长:python、mysql、java
<p>由于您是Python新手,这里有一个简单的方法可以做到这一点,而不需要太复杂的语法:</p>
<pre><code># For each tuple inside daily_sales
for sale in daily_sales:
# Use the first element of that tuple as a key and check if it's inside the dictionary budgeted_sales
if sale[0] in budgeted_sales:
# Compare the value stored for that key with the second element of the tuple (which contains the other price) and print stuff
if budgeted_sales[sale[0]] > sale[1]: print('Over')
else: print('Under')
</code></pre>
<p>上面的检查是可选的,但是它确保您不会用不存在的键直接访问字典,然后尝试用存在的值添加不存在的值。你知道吗</p>