I'm writing a code which takes a list of numbers, some of which are very close or equal to other elements of the list, for example [0.1,0.101,0.2,0.499,0.5], then returns a smaller list of the main numbers the elements of this list fall close to, so in this case [0.1005,0.2,0.4995].
At the moment my code would return the first number from each category from the list, so here it returns [0.1,0.2,0.499], but I need more accuracy.
Here's my current code:
def listsort(x):
deletelist = []
for i in range(len(x)):
for j in range(i+1,len(x)):
if abs(x[i]-x[j])<1e-5:
deletelist.append(x[j])
for j in deletelist:
x.remove(j)
return x