Review generated reading index

from Tuples
Python 3.14 advanced 6 min 4 issues to find

Review this generated reading-index implementation.

Build an index keyed by normalized station and tag set. Reject empty readings, store an immutable reading tuple with its mean, and support mean lookup.

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]

generated code is illustrative, not from any one model

Open in playground
Report an error