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 set
s 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
Post a Comment