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]]



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

Read more here:

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: