I have the following lines of code that are used in a function:
a = [1, 2, 4, 1]
b = [1, 3, 4, 1]
return [a for i in range(len(a)) if a[i] == b[i] and a not in *self*]
It should return [1, 4].
I want to use something similar to the self
value in classes.
I can do something like this:
a = [1, 2, 4, 1]
b = [1, 3, 4, 1]
lst = []
for i in len(a):
if a[i] == b[i] and a[i] not in lst:
lst.append(a[i])
return lst
or even this
a = [1, 2, 4, 1]
b = [1, 3, 4, 1]
return list(set([a for i in range(len(a)) if a[i] == b[i]]))
(Note that this method may change the order of the items in the list.)