def multi_search(words, text, ms=None): if ms is None: ms = MultiSearch(words) results = [] def callback(pos, word): results.append((pos, word)) return False ms.search(text, callback) results.sort() return results