Michael Michael - 3 months ago 7
Python Question

Seeing if an element from a 1D array is in another MD array

array1D = ['book', 'aa', 'Ab', 'AB']
arrayMD = ['ss', 'book', 'fd', '2'], ['sw', 'd'], ['we', 'wr']


How could I check to see if any element in array1D exists in arrayMD?

So far I just know of the find() method and that seems to only work for one element search.

Edit: I'd like to get it's index from arrayMD as well

Answer

Use in.

for sublist in arrayMD:
    for index, element in enumerate(sublist):
        if element in array1D:
             # Do something