import numpy as np
x = [10.01, 5.001, 4.89, 5.1, 9.9, 10.1, 5.05, 4.99]
x = np.sort(x)
th = 0.5
print([group.mean() for group in np.split(x, np.where(np.diff(x) > th)[0] + 1)])
sort list of floating-point numbers in groups