I have a list = [1, 2, 3, 3, 6, 8, 8, 10, 2, 5, 7, 7] I am trying to use groupby to convert it into
1
2
3
3
6
8,8
10
2,
5
7,7
Basically, anything greater then 6, I like to group them, otherwise I want to keep them ungrouped. Any hint on how I can do this with itertool groupby
My code currently:
for key, group in it.groupby(numbers, lambda x: x):
f = list(group)
if len(f) == 1:
split_list.append(group[0])
else:
if (f[0] > 6): #filter condition x>6
for num in f:
split_list.append(num + 100)
else:
for num in f:
split_list.append(num)