Skip to content
Advertisement

How to remove from these 2 lists of lists the possible lists that appear in both lists of lists?

These are the two lists, both of which have the same number of elements:

JavaScript

I try with this:

JavaScript

but I get this error when trying to subtract the elements that are the same in both lists

JavaScript

I need the lists to be like this, that is, within each of them there are only those elements that are different:

JavaScript

How could I achieve this? (if possible without using additional libraries, although if there is no other way I would have no problem using them)

Advertisement

Answer

You should use zip to iterate the lists in parallel, and another zip to separate the output back in two lists:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement