fork(4) download
  1. from itertools import groupby
  2.  
  3. arr = [1.112, 1.113, 1.114, 1.111, 1.221, 1.223, 1.321, 1.021, 1.03, 2.0, 3.6, 4.2]
  4.  
  5.  
  6. result = groupby(arr, key=lambda x: int(x * 10) if 1 <= x < 2 else -1)
  7.  
  8. for key, vals in result:
  9. print(key / 10, list(vals))
Success #stdin #stdout 0.02s 9312KB
stdin
Standard input is empty
stdout
1.1 [1.112, 1.113, 1.114, 1.111]
1.2 [1.221, 1.223]
1.3 [1.321]
1.0 [1.021, 1.03]
-0.1 [2.0, 3.6, 4.2]