我正在努力为这个问题正确命名,但我会尝试解释这种情况。
我有两个清单
l1=['beststreet', 'borocd', 'am_linkid3', 'bestfrom', 'resurf19', 'rmmweekly']
l2=['beststreet', 'borocd', 'bestfrom', 'rmmweekly','weird','noises']
l1 将始终保持不变。
l2 可以包含与 l1 相同的项目,也可以仅包含 l1 中的一些项目,并且在任何情况下,列表中都可以有额外的项目。
目标:只找到 l2 中 l1 中缺失的项目(忽略 l2 中的额外项目)
这是我的完整代码,它工作得很好,我只是觉得我想多了,我想要的可以有一个更简单的 Pythonic 工作流程
l1=['beststreet', 'borocd', 'am_linkid3', 'bestfrom', 'resurf19', 'rmmweekly']
l2=['beststreet', 'borocd', 'bestfrom', 'rmmweekly','weird','noises']
result = [[n if n in l1 else None, n if n in l2 else None] for n in set(l1 + l2)]
missing_columns=[]
for r in result:
if None in r:
exists= [z for z in l1 if z in r]
if exists:
missing_columns.append(exists[0])
print missing_columns
print([item for item in l1 if item not in l2])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句