>>> [(x[0:2] + (sum(z[2] for z in y),) + x[2:5]) for (x, y) in itertools.groupby(sorted(L, key=operator.itemgetter(0, 1, 3, 4)), key=operator.itemgetter(0, 1, 3, 4))][ ('A', '', Decimal('21.0000000000'), 1330, datetime.datetime(2012, 5, 14, 0, 0)), ('A', '', Decimal('4.0000000000'), 1330, datetime.datetime(2012, 6, 8, 0, 0)), ('AA', 'C', Decimal('31.0000000000'), 1330, datetime.datetime(2012, 5, 31, 0, 0)), ('B', '', Decimal('7.0000000000'), 1330, datetime.datetime(2012, 5, 24, 0, 0)), ('B', '', Decimal('31.0000000000'), 1330, datetime.datetime(2012, 6, 4, 0, 0))]
(注意:重新格式化输出)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)