l=[[15.0, 10265.0, 1860.0, 142600.0, 3],[12.0, 14631.0, 3298.0, 153100.0, 2],[22.0, 1707.0, 296.0, 126600.0, 3],[7.0, 1737.0, 290.0, 147000.0, 2]]
If i want to get two lists:
[[15.0, 10265.0, 1860.0, 142600.0, 3],[22.0, 1707.0, 296.0, 126600.0, 3]] [[12.0, 14631.0, 3298.0, 153100.0, 2],[7.0, 1737.0, 290.0, 147000.0, 2]]
how do i do this using itertools? is there any other way to do this?
l1=[]
key_func = lambda x: x[-1]
for key, group in itertools.groupby(l, key_func):
l1.append(list(group))
I tried this but i got [[[15.0, 10265.0, 1860.0, 142600.0, 3]], [[12.0, 14631.0, 3298.0, 153100.0, 2]], [[22.0, 1707.0, 296.0, 126600.0, 3]], [[7.0, 1737.0, 290.0, 147000.0, 2]]]