Am trying to create a groups from the array by target index
for example this my Array
Am trying to target index [1] of each child of the data array
data = [('0', 'COL1', 'date'),('1', 'COL2', 'date'), ('2', 'COL1', 'date'), ('3', 'COL3', 'date') , ('4', 'COL1', 'date'),('6', 'COL2', 'date')]
expected output is
[[('0', 'COL1', 'date'),('2', 'COL1', 'date'),('4', 'COL1', 'date')],[('1', 'COL2', 'date'),('6', 'COL2', 'date')],[('3', 'COL3', 'date')]]
Thank you any help will appreciated!
itertools.groupby?[list(g) for k, g in groupby(sorted(data, key=lambda L: L[1]), lambda L: L[1])]