I am trying to group data based on second argument.
test= [(1,1),(3,1),(5,0),(3,0),(2,1)]
I am excuting code from this thread
from itertools import groupby
from operator import itemgetter
result = [list(group) for key, group in groupby(test, itemgetter(1))]
But instead of getting a result that look like: [[(1,1),(3,1),(2,1)],[(5,0),(3,0)]]
Why I am getting the last tuple in a seperated list, while I should get it grouped with other values where 1 is a second values
[[(1,1),(3,1)],[(5,0),(3,0)],[(2,1)]]