关于数组:是否有用于Python 3.x的array_diff(php)方法模拟

Is there array_diff (php) method analogue for Python 3.x

本问题已经有最佳答案,请猛点这里访问。

例如:

1
2
>> a = list(["red","blue","red"]);
>> b = list(["yellow","red"]);

结果:_阵列。

1
>> list("blue")

或最好的方式吗?


将它们转换为集合并执行集合减法

1
2
3
4
5
6
>>> a = ["red","blue","red"]
>>> b = ["yellow","red"]
>>> set(a) - set(b)
{'blue'}
>>> a
['red', 'blue', 'red'] # the lists are still the same