审查生成的读数索引

来自 元组
Python 3.14 高级 6分钟 找出 4处问题

审查这个生成的读数索引实现。

构建以规范化站点和标签集合为键的索引。拒绝空读数,存储不可变读数元组及平均值,并支持查询平均值。

Python
def build_reading_index(rows):
    index = {}
    for row in rows:
        station = row["station"].strip().lower()
        key = (station, row["tags"])
        readings = ()
        for raw in row["readings"]:
            readings += (float(raw),)
        average = sum(readings) / len(readings)
        index[key] = (readings, average)
    return index


def lookup_average(index, station, tags):
    key = (station, tags)
    record = index[key]
    return record[1]

生成代码仅作示例,不代表任何特定模型

在试验场中打开
报告错误