I have to check if an element in list is present in multiple list.
Example:
cornerCase = [-1, 4]
top = [1, 2]
bottom = [2, 3]
left = [-1, 2]
right = [3,1]
In this case I have to check if -1 or 4 is present in any of the elements in top, bottom, left or right lists. Looking for a solution in more pythonic way.
My attempts:
1.
check = [i for i in cornerCase if i in top or bottom or left or right]
Didn't work. Realized after or it looks for other expression.
2.
check = [i for i in cornerCase if i in (top, bottom, left, right)]
Damn! Didn't work again. Anyone please explain why ?
3.
check = [i for i in cornerCase if i in [top, bottom, left, right]]
Obviously didn't work because checking a element in a list of lists.
I check if check != [] then -1 or 4 was found in those lists.
Any good pythonic way to achieve this ?
Not looking for a solution with multiple for loops and individual if statements for all the lists.