[Tutor] finding words that contain some letters in their respective order

Andre Engels andreengels at gmail.com
Sat Jan 24 00:57:59 CET 2009


I made an error in my program... Sorry, it should be:

def hasRoot(word, root): # This order I find more logical
   loc = 0
   for letter in root:
        loc = word.find(letter,loc) # I missed the ,loc here...
        if loc == -1:
            return false
   return true

# main

infile = open("myCorpus.txt").read().split()
query = "ktb"
outcome = [word for word in infile if hasRoot(word,query)]


-- 
André Engels, andreengels at gmail.com


More information about the Tutor mailing list