python找到两个列表之间的区别 [英] python find difference between two lists

查看:114
本文介绍了python找到两个列表之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手,但我一直在学习,最近我碰壁了,所以我寻求帮助. 抱歉,如果之前已经讨论过,但是我找不到我的问题的答案. 我有两个清单.我需要比较它们,并在结果中得到不匹配的对象.例如:

I am new to programming but I keep learning, and recently I hit the wall so I'm asking for help. Sorry if this was discussed before, but I can't find answer to my problem. I have two lists. And I need to compare them, and in the result to get the objects that DON'T match. For example:

a = [1,2,3,4,5,6]
b = [1,2,3,4,5,6,7,8,9]
result = [7,8,9].

我似乎只找到返回匹配项的代码和示例.我不需要.

And I only seem to find code and examples that return matches. Which I don't need.

列表位于文件记事本file.txt 中,如果您有帮助,请您记住. :)

Lists are in file notepad file.txt for you folks to keep in mind if you this helps you to help me. :)

推荐答案

您可以将列表转换为集合并运行常规的

You can convert the lists to sets and run the usual set operations such as difference or symmetric difference. For example, set(b) - set(a) evaluates to set([7, 8, 9]).

这篇关于python找到两个列表之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆