Is there a more Pythonic way to write the code beneath, so that it iterates over some condition but also keeps an index of the iterations?
def TrieMatching(text, trie):
match_locations = []
location = 0
while text:
if PrefixTrieMatching(text, trie):
match_locations.append(location)
text = text[1:]
location += 1
I'm always fond of list comprehensions.
def TrieMatching(text, trie):
match_locations = [
location
for location in range(len(text))
if PrefixTrieMatch(text[location:],trie)
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With