the idea is to group same/similar float numbers, excluding drastic differences.
For example group 1.123 and 1.123, 1.322 also consider 2.01 as being in one group (additional condition is required to take into account +1 or -1).
code:
from itertools import groupby
x =[39.5999755859375,48.84002685546875,58.08001708984375,67.32000732421875,76.55999755859375,85.79998779296875,147.83999633789062,147.95999145507812,147.95999145507812,147.95999145507812,147.95999145507812,148.07998657226562,147.95999145507812,147.95999145507812,147.95999145507812,147.95999145507812,199.07998657226562,199.07998657226562,199.07998657226562,199.07998657226562,199.07998657226562]
groups = [list(g) for _, g in groupby(x, key=int)]
output:
groups
Out[129]:
[[39.5999755859375],
[48.84002685546875],
[58.08001708984375],
[67.32000732421875],
[76.55999755859375],
[85.79998779296875],
[147.83999633789062,
147.95999145507812,
147.95999145507812,
147.95999145507812,
147.95999145507812],
[148.07998657226562],
[147.95999145507812,
147.95999145507812,
147.95999145507812,
147.95999145507812],
[199.07998657226562,
199.07998657226562,
199.07998657226562,
199.07998657226562,
199.07998657226562]]
As you can see in the output [148.07998657226562] is considered as being different instead of being among 147's
Is there any condition or function I could use inside of groupby() as a parameter to explicitly give a condition/ to take into account all those similar numbers such as 147 and 148 (+- 1).