1
回答
python list groupby itertools
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   
gp_jy_list  = [
[-1300L,  '5.390', '2013-05-27', '600701'], 
[900L,  '6.840', '2013-05-28', '600525'], 
[700L,  '9.550', '2013-05-28', '600735'], 
[-700L,  '9.670', '2013-05-29', '600735'], 
[-900L,  '6.890', '2013-05-29', '600525']

]



from itertools import  groupby

group_result = groupby(gp_jy_list , lambda item:item[3])


for k, group in group_result :

    print k , list(group)


out put 

600701 [[-1300L, '5.390', '2013-05-27', '600701']]
600525 [[900L, '6.840', '2013-05-28', '600525']]
600735 [[700L, '9.550', '2013-05-28', '600735'], [-700L, '9.670', '2013-05-29', '600735']]
600525 [[-900L, '6.890', '2013-05-29', '600525']]


难道要先sort? 太二了吧。

举报
阿鹅分
发帖于5年前 1回/1K+阅
顶部