Michael Michael - 5 months ago 13
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


Use in.

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