Fluxy
Fluxy

Reputation: 2978

How to test for substrings in the list

I need to check if a string is in the list my_list.

my_list = ['word1,word2,word3', 'g1,g2', 'word1']

When I run 'word2' in my_list, it returns False instead of True.

How can I test for substrings in the list?

Upvotes: 0

Views: 54

Answers (1)

B1TC0R3
B1TC0R3

Reputation: 131

You have to check whether your string is part of each list element.

Something like this:

for elem in my_list:
    if 'word_2' in elem: return True

Upvotes: 1

Related Questions