Add to a list based on previous value

I am trying to group this list together

Example input

M1 = [['a', 14], ['a',7], ['a',16],['b',3],['b',15],['c',22],['c',1],['c',5]]

Output

[['a',14,7,16],['b',3,15],['c',22,1,5]]

Meaning group all the 'a' value together same goes for 'b', 'c' and so on



Read more here: https://stackoverflow.com/questions/67394188/add-to-a-list-based-on-previous-value

Content Attribution

This content was originally published by Ken Uda at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: