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

时间:2016-10-09 10:26:01

标签: python arrays

例如:

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

array_diff的结果:

>> list("blue")

或最好的方法吗?

1 个答案:

答案 0 :(得分:0)

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

>>> a = ["red", "blue", "red"]
>>> b = ["yellow", "red"]
>>> set(a) - set(b)
{'blue'}
>>> a
['red', 'blue', 'red'] # the lists are still the same
相关问题