Ockonal Ockonal - 1 year ago 95
Python Question

Check list of words in another string

I can do such thing in python:

list = ['one', 'two', 'three']
if 'some word' in list:

This will check if 'some word' exists in the list. But can I do reverse thing?

list = ['one', 'two', 'three']
if list in 'some one long two phrase three':

I have to check whether some words from array are in the string. I can do this using cycle but this way has more lines of code.

Answer Source
if any(word in 'some one long two phrase three' for word in list_):
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download