Word break problem: Difference between revisions
Content deleted Content added
Line 774:
# tokenTrees :: [String] -> String -> [Tree String]
def tokenTrees(wds):
def parse(w, xs):▼
return [Node(w)(xs)] if xs else xs▼
def go(s):
return [Node(s)([])] if s in wds else (
Line 786 ⟶ 783:
w, go(s[len(w):])
) if s.startswith(w) else []
▲ def parse(w, xs):
▲ return [Node(w)(xs)] if xs else xs
return lambda s: go(s)
|