Day12(Python作业)
(Python作业来自qq群:651707058,欢迎任何程度的Python学习者)
题一:数字相加
[[‘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了)
def num_add(L):
'''
:param L:list[list] 原数据
:return: dict 字典 字母为key 数为value
'''
res = {}
for i,v in L:
if i not in res:
res[i] = int(v)
else:
res[i]+=int(v)
#print(i,v)可以理解一下for i,v in L:的意义
return res
L = [['A','1'],['B','2'], ['C','3'], ['A','4'], ['B','5'], ['C','6'], ['A','1'], ['B','