Skip to content

Instantly share code, notes, and snippets.

@mjgpy3
Created August 6, 2016 18:01
Show Gist options
  • Save mjgpy3/d761eb270ac9f63b7e039401ba1949f8 to your computer and use it in GitHub Desktop.
Save mjgpy3/d761eb270ac9f63b7e039401ba1949f8 to your computer and use it in GitHub Desktop.
Group By Python
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