So i have two lists a normal list and a nested list say,
list1 = ['john','amal','joel','george']
list2 = [['john'],['jack','john','mary'],['howard','john'],['jude']]
I would like to check if any of the string in list1 is present in list2 and if so, return the indices of the string (which is in both the lists) in list2. Sample code which demonstrates the required output is shown below:
out = [(ind,ind2) for ind,i in enumerate(list2)
for ind2,y in enumerate(i) if 'john' in y]
print out
it returns : [(0, 0), (1, 1), (2, 1)]
the above code does output the indices but it is limited to the string that we manually input. Is it possible to do as i have explained above? any help would be appreciated.(fairly new to nested lists). Thanks!