python - Find similar value exists in multiple lists -


i have 3 arrays l1,l2 & l3 , each element on list unique across 3 list. have array q has values needs checked in arrays l1,l2 & l3 , if present should output array name

note: values of q may in between values of l1,l1 or l3

example list:

q= ['abc','def','ghi',' gggg','cc '] l1 = ['aa abc','bb bb','cc cc'] l2 = ['ddd ddd','eee def eee','fff fff'] l3 = ['gggg gggg','hhhh hhhh','ghi iiii'] 

the code should this

for value in q   if value  in l1:       elif value  in l2:       elif value  in l2:       else:     "nil" 

the ouput should be:

l1 l2 l3 l3 l1 

thanks in advance..

since dealing substrings need check individual elements in each list:

q = ['abc','def','ghi',' gggg','cc '] l1 = ['aa abc','bb bb','cc cc'] l2 = ['ddd ddd','eee def eee','fff fff'] l3 = ['gggg gggg','hhhh hhhh','ghi iiii'] all_lists = [l1, l2, l3]  val in q:     i, li in enumerate(all_lists):         li_val in li:             if val in li_val:                 print('{} in l{}'.format(val, + 1)) 

outputs:

abc in l1 def in l2 ghi in l3  gggg in l3 cc  in l1 

note don't have direct access lists' names since objects don't keep track of names reference them. use dictionary names still need hard-coded.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -