Python: Check if a value is in each list in a list of lists -


i have question regarding if quick way exist check if each value in list in each sublist of list of lists.

word = ['elevator','cats allowed','hardwood floors',...] # length 100. no duplicate exists in list. features =[['hardwood floors','doorman',...],['pre-war', 'dogs allowed', 'cats allowed',...],[...]] # list of lists;length ~150,000 

what know can double loop iterate on word , features. wondering if there quicker way? because found double loop slow in case.

what expect like:

for each_word in word:     each_word in features?  

i wish every iteration on word, returns vector of boolean each_word (namely, if each_word in every sublist of features, returns vector of true [true,true,....,true];if each_word not in sublist, returns vector of false; otherwise if returns mixed vector of true or false.

thank you

if want know if of words in of lists:

 set(words).issubset(set([item sublist in features item in sublist])) 

edit: ok, if want know if each word in list, do:

s = set([item sublist in features item in sublist] [word in s word in words] 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -