Skip to content

Instantly share code, notes, and snippets.

@mooreniemi
Created October 22, 2012 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooreniemi/3933483 to your computer and use it in GitHub Desktop.
Save mooreniemi/3933483 to your computer and use it in GitHub Desktop.
for 600x
def getGuessedWord(secretWord, lettersGuessed):
'''
secretWord: string, the word the user is guessing
lettersGuessed: list, what letters have been guessed so far
returns: string, comprised of letters and underscores that represents
what letters in secretWord have been guessed so far.
'''
count = 0
blank = ['_'] * len(secretWord)
#print blank
for i, c in enumerate(secretWord):
if c in lettersGuessed:
count += 1
#print count
blank.insert(count-1,c)
blank.pop(count)
#print blank
if count == len(secretWord):
return ''.join(str(e) for e in blank)
else:
count += 1
blank.insert(count-1,'_')
blank.pop(count)
if count == len(secretWord):
return ''.join(str(e) for e in blank)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment