If I have an list of strings:
matches = [ 'string1', 'anotherstring', 'astringystring' ]
And I have another string that I want to test:
teststring = 'thestring1'
And I want to test each string, and if any match, do something. I have:
match = 0
for matchstring in matches:
if matchstring in teststring:
match = 1
if !match:
continue
This is in a loop, so we just go around again if we don't get a match (I can reverse this logic of course and do something if it matches), but the code looks clumsy and not pythonic, if easy to follow.
I am thinking there is a better way to do this, but I don't grok python as well as I would like. Is there a better approach?
Note the "duplicate" is the opposite question (though the same answer approach is the same).