def get_closest_stamp(ts):
    """Speed-up timestamp search by looking only at entries in the same hour"""
hour = round_to_nearest_hour(ts)
cluster = daydict[hour]
return min(cluster, key=lambda t: abs(ts - t))
Python - Locating the closest timestamp