ls = 'my long string of stuff'
x = set([ls[p:y] for p in range(0, len(ls) + 1) for y in range(p + 1, len(
    ls) + 1)])
result = []
for word in A:
    if word in x:
        pass
High performance mass short string search in Python