Python: How do I compare all items in one list as a string to all items in another list? -


for each_word1 in list_a:     ###compare values to...###     each_word2 in list_b:         if each_word2 in list_b == any_word in list_a:             add each_word2 list_c             ###something that### 

python have figure of sets ideal situation this. these data structures excel in fast comparison of containment, , has same primitive operations have in basic math in first school grades.

just convert 1 of lists set (this remove duplcates if any), , use intersection operation. convert result list if need:

list_c = list(set(list_a).intersection(list_b)) 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -