# rangerecordreduce table1 = [['foo', 'bar'], ['a', 3], ['a', 7], ['b', 2], ['b', 1], ['b', 9], ['c', 4]] from petl import rangerecordreduce, look look(table1) def redu(minv, maxunpack, recs): return [minv, maxunpack, ''.join([rec['foo'] for rec in recs])] table2 = rangerecordreduce(table1, 'bar', 2, reducer=redu, fields=['frombar', 'tobar', 'foos']) look(table2) # rangecounts table1 = [['foo', 'bar'], ['a', 3], ['a', 7], ['b', 2], ['b', 1], ['b', 9], ['c', 4], ['d', 3]] from petl import rangecounts, look