I have a string and list of unique substrings. The problem is to identify, which substrings occur in our string.
It can be done simply with 2 nested loops.
result = []
substrings = ['foo', 'bar', 'spam', 'eggs']
text = 'foo123123spameggsabcde'
for s in substrings:
if s in text:
result.append(s)
But it is slow, especially whith long string and many substrings. Is there a way to perform this more efficiently?