擅长:python、mysql、java
<p>这将从测试数据中生成所需的输出:</p>
<pre><code>data = [(0.1,100), (0.13,300), (0.2,10)]
buckets = [((0,0.14), 2), ((0.135,0.19), 1), ((0.19,0.21), 2), ((0.19,0.24), 3)]
totals = dict()
for bucket in buckets:
bucket_id = bucket[1]
if bucket_id not in totals:
totals[bucket_id] = 0
for data_point in data:
if data_point[0] >= bucket[0][0] and data_point[0] <= bucket[0][1]:
totals[bucket_id] += data_point[1]
for key in sorted(totals):
print("{}: {}".format(key, totals[key]))
</code></pre>