ywh123456 最近的时间轴更新
ywh123456

ywh123456

V2EX 第 322001 号会员,加入于 2018-06-11 22:20:23 +08:00
ywh123456 最近回复了
2018-06-12 07:58:42 +08:00
回复了 webing 创建的主题 Python Python 两个大列表如何对比相同内容并合并?
from collections import defaultdict
a = [
['11', 'wqdqwdwd', '允许撒大声地'],
['22', 'ewrdwewd', '允许打发斯蒂'],
['33', 'hghfgfgh', '允许撒大我地'],
['44', 'gfdgdgrg', '允许伟大无多']
]

b = [
['22', 'jhgfghfgh', '允许 dawdadd'],
['33', 'hfghgffgh', '允许 wadawwa'],
['44', 'jyjygjyyd', '允许 dwadwad'],
['11', 'ikluhkmug', '允许 dwadwad']
]

c = defaultdict(list)
for tmp in a + b:
c[tmp[0]].append(tmp)

#输出
for key in c.keys():
print("{} has {}".format(key,c[key]))
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2671 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 15ms · UTC 14:58 · PVG 22:58 · LAX 06:58 · JFK 09:58
Developed with CodeLauncher
♥ Do have faith in what you're doing.