# list 求助

3 messages
Open this post in threaded view
|
Report Content as Inappropriate

## list 求助

 This post has NOT been accepted by the mailing list yet. 初学Python  花了一天的时间考虑如何循环，写出代码总是缺少数值，请帮助，谢谢！  已知一下两个list，len(Alist)=len(Blist),求Alist[i]中相同的Blist[i]的和：  Alist=['10A','10A','10A','11A','11A','12A','12A','12B','12B','12B','12B','12B','12B','12B','13C']  Blist=[15,25,30,40,50,12,20,35,42,15,15,13,32,14,56]  如何得到AVlist和BVlist:  AVlist=['10A','11A','12A','12B','13C']  BVlist=[60,90,32,151,56]  请问如何根据Alist和Blist得到AVlist和BVlist，谢谢！-- Now found Gmail was so powerful
Open this post in threaded view
|
Report Content as Inappropriate

## Re: list 求助

 This post has NOT been accepted by the mailing list yet. Alist=['10A','10A','10A','11A','11A','12A','12A','12B','12B','12B','12B','12B','12B','12B','13C'] Blist=[15,25,30,40,50,12,20,35,42,15,15,13,32,14,56] SUM = {} for i in range(len(Alist)):    item = Alist[i]    if item in SUM.keys():       SUM[item] += Blist[i]    else:       SUM[item] = Blist[i] A= [item for item in SUM.keys()] B= [item for item in SUM.values()] print A print B