python 练习题
程序员文章站
2022-07-16 13:05:18
...
[['A','1'],['B','2'], ['C','3'], ['A','4'], ['B','5'], ['C','6'], ['A','1'], ['B','1'], ['C','1']]分别将这里面的A所对应的数都相加,B所对应的数相加,C所对应的数相加
这里面的A,B,C是随机的 有可能下回就是G,H,I了
list=[['A','1'],['B','2'], ['C','3'], ['A','4'], ['B','5'], ['C','6'], ['A','1'], ['B','1']] dic={'A':'0','B':'0','C':'0'} print type(dic.get('A')) print type(int(dic.get('A'))) #print elem[0],':',(int(dic.get(elem[0]))+int(elem[1])) for elem in list: dic[elem[0]]=str(int(dic.get(elem[0]))+int(elem[1])) print dic