Skip to content Skip to sidebar Skip to footer

Searching List Using Keywords From Other List?

Say I have this list some_list = [ 'red apple', 'red banana', 'house is green', 'blue road', 'blue hat' ] I want to specify my keywords in another list. search

Solution 1:

Solution 2:

[[words forwordsin some_list if kw in words.split()] forkwin search_strings]

That gives you:

[['red apple', 'red banana'], ['house is green']]

Also, if the "sencences" in some_list or the length of search_strings get bigger, it might pay to convert them to sets (like search_strings = set(search_strings)).

Post a Comment for "Searching List Using Keywords From Other List?"