0
def isWordGuessed(secretWord, lettersGuessed):
'''
secretWord: string, the word the user is guessing
lettersGuessed: list, what letters have been guessed so far
returns: boolean, True if all the letters of secretWord are in lettersGuessed;
False otherwise
'''
certas =0
for i in range(len(secretWord)):
if secretWord[i] in lettersGuessed:
certas += 1
#print(certas)
if certas == len(secretWord):
return True
else:
return False
secretWord = 'durian'
#lettersGuessed = ['e', 'i', 'k', 'p', 'r', 's']
#lettersGuessed = ['e', 'a', 'l', 'p', 'e']
#isWordGuessed('durian', ['h', 'a', 'c', 'd', 'i', 'm', 'n', 'r', 't', 'u'])
lettersGuessed = ['h', 'a', 'c', 'd', 'i', 'm', 'n', 'r', 't', 'u']
print(isWordGuessed(secretWord, lettersGuessed))
Purpose is to determine whether all letters of secretWord are contained in lettersGuessed.
My code is working. Is there any Pythonic way to do?
all is a function?
– Ed S
Yes. It doesn’t even have to matter. It’s worth knowing
alland her sisterany.– Pedro von Hertwig Batista
You can remove the clasps inside
allto, instead of creating a list, create a generator. So the interpreter will only need to evaluate until it finds the firstfalse, which can save time and application memory.– Woss