Created
August 6, 2016 18:01
-
-
Save mjgpy3/d761eb270ac9f63b7e039401ba1949f8 to your computer and use it in GitHub Desktop.
Group By Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import groupby | |
values = [ | |
['1', 'r1', '100'], | |
['1', 'r2', '100'], | |
['1', 'r3', '105'], | |
['1', 'c1', '100'] | |
] | |
def grouping_factor(row): | |
return (row[1][0], row[2]) | |
for k, v in groupby(values, grouping_factor): | |
print list(v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment