What am I doing wrong here?
[color=blue][color=green][color=darkred]
>>> import operator
>>> import itertools
>>> vals = [(1, 11), (2, 12), (3, 13), (4, 14), (5, 15),[/color][/color][/color]
.... (1, 16), (2, 17), (3, 18), (4, 19), (5, 20)][color=blue][color=green][color=darkred]
>>> for k, g in itertools.group by(iter(vals), operator.itemge tter(0)):[/color][/color][/color]
.... print k, [i for i in g]
....
1 [(1, 11)]
2 [(2, 12)]
3 [(3, 13)]
4 [(4, 14)]
5 [(5, 15)]
1 [(1, 16)]
2 [(2, 17)]
3 [(3, 18)]
4 [(4, 19)]
5 [(5, 20)]
What I want is tuples starting with identical numbers to be grouped. I
cannot figure out why this is not working. If anyone has any insights,
I would appreciate it.
- Alex Ross
[color=blue][color=green][color=darkred]
>>> import operator
>>> import itertools
>>> vals = [(1, 11), (2, 12), (3, 13), (4, 14), (5, 15),[/color][/color][/color]
.... (1, 16), (2, 17), (3, 18), (4, 19), (5, 20)][color=blue][color=green][color=darkred]
>>> for k, g in itertools.group by(iter(vals), operator.itemge tter(0)):[/color][/color][/color]
.... print k, [i for i in g]
....
1 [(1, 11)]
2 [(2, 12)]
3 [(3, 13)]
4 [(4, 14)]
5 [(5, 15)]
1 [(1, 16)]
2 [(2, 17)]
3 [(3, 18)]
4 [(4, 19)]
5 [(5, 20)]
What I want is tuples starting with identical numbers to be grouped. I
cannot figure out why this is not working. If anyone has any insights,
I would appreciate it.
- Alex Ross
Comment