Reputation: 8131
Here is my code:
def detLoser(frag, a):
word = frag + a
if word in wordlist:
lost = True
else:
for words in wordlist:
if words[:len(word) == word:
return #I want this to break out.
else:
lost = True
Where I have a return, I've tried putting in both return and break and both give me errors. Both give me the following error: SyntaxError: invalid syntax. Any Ideas? What is the best way to handle this?
Upvotes: 0
Views: 250
Reputation: 304147
def detLoser(frag, a):
word = frag + a
if word in wordlist:
lost = True
else:
for words in wordlist:
if word.startswith(words):
return #I want this to break out.
else:
lost = True
you can probably rewrite the for loop using any
or all
eg. ( you should use a set instead of a list for wordlist though)
def detLoser(frag, a):
word = frag + a
return word in wordlist or any(w.startswith(word) for w in wordlist)
Upvotes: 2
Reputation: 123632
You've omitted the ]
from the list slice. But what is the code trying to achieve, anyway?
foo[ : len( foo ) ] == foo
always!
I assume this isn't the complete code -- if so, where is wordlist
defined? (is it a list? -- it's much faster to test containment for a set.)
Upvotes: 6