I have a list A
and list B
, I want to get common elements from the two lists but want when I get the common elements they should maintain the order of List A
.
First I started with converting them in to set and taking the intersection but that had the problem of maintaining the order.
common = list(set(A).intersection(set(B)))
so I decided to do list comprehension:
common = [i for i in A if i in B]
I am getting
IndexError: too many indices for array