from itertools import groupby
>>> l = [['a',5], ['e',5], ['c',3], ['d',3],['e',1]]
for k, v in groupby(l, lambda x: x[1]):
... ... print([a for a, _ in v] + [k])
...
['a', 'e', 5]
['c', 'd', 3]
['e', 1]
python
built-in
module has many good functions.
I recommend you take a look at what's there.
© 2024 OneMinuteCode. All rights reserved.