I have a list of timestamps and a key timestamp to find the nearest one, both are in the format '2019-11-22T11:37:52.338Z'
I have tried this solution Python - Locating the closest timestamp but since my timestamps are in string
leads me with an error. When I tried to typecast them as shown below
def nearest(ts):
s = sorted(timestamp_list)
i = bisect_left(s, ts)
return min(s[max(0, i-1): i+2], key=lambda t: abs(int(ts) - int(t)))
ends up with ValueError: invalid literal for int() with base 10: '2019-11-22T11:37:52.338Z'
Any suggestions on how to overcome this error?