Hello,
I have two lists that returns some vector values with it's own name:
list1 = [['orange', [1, 2, 3]]]
list2 = [['apple', [1, 2, 3]], ['banana', [1, 2, 3]], ['pear', [-1, 2, 3]], ['kiwi', [1, -2, 3]]]
So far I have a code that uses the list1 as a "search key" and ignoring the string on the list2 and print out the sublist that are not the same than in list1, which gives this result:
[['pear' [-1, 2, 3], ['kiwi', [-1, -2, 3]]]
This is the script:
<pre><pre lang="Python">S = set(tuple(x[1]) for x in list1)
result = [x for x in list2 if tuple(x[1]) not in S]
The current code I have working returns the correct result by ignoring the strign, but I would like to go futher and compare only the first value of the vector list, which the result should be:
[['pear' [-1, 2, 3]] only eventhough kiwi has different value but in the second item of the vector list.
What I have tried:
S = set(tuple(x[1]) for x in list1[0])
result = [x for x in list2[0] if tuple(x[1]) not in S]
but it gives a TypeError since is a tuple and not strings