arr = [['黑','1101'], ['黑','1101'], ['白','1201'], ['黑','1102']]
如何得到以下结果黑 3黑 1101 2白 1
也就是说要知道每个颜色一共多少,其中哪几个序号是重复的,重复次数是多少?
想了好久也无从下手,哪位高手有过类似经验请指教!!!
1 回答
慕田峪4524236
TA贡献1875条经验 获得超5个赞
from collections import Counter
data = [['黑','1101'], ['黑','1101'], ['白','1201'], ['黑','1102']]
c1 = Counter(d[0] for d in data)
for k,v in c1.items():
print(k, v)
c2 = Counter(''.join(d) for d in data)
for k, v in c2.items():
print(k, v)
添加回答
举报
0/150
提交
取消