1

for example:

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

result of array_diff:

>> list("blue")

or best way to do this?

SlowSuperman
  • 488
  • 1
  • 8
  • 14
  • Is the order of elements in the resulting list important? If not you can convert both of them to sets and find the set difference `set(a) - set(b)` – thefourtheye Oct 09 '16 at 10:28
  • You can use: `[item for item in a if item not in b]` and wrap this in a function, but I do not know if there is a built-in solution out of the box – Jakub Jankowski Oct 09 '16 at 10:29

1 Answers1

1

convert them to a set and do a set substraction

>>> a = ["red", "blue", "red"]
>>> b = ["yellow", "red"]
>>> set(a) - set(b)
{'blue'}
>>> a
['red', 'blue', 'red'] # the lists are still the same
danidee
  • 9,298
  • 2
  • 35
  • 55