Skip to content

Instantly share code, notes, and snippets.

@maxandersen
Created March 24, 2023 12:30
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 maxandersen/42182eb242b30e43aff53bba44c23070 to your computer and use it in GitHub Desktop.
Save maxandersen/42182eb242b30e43aff53bba44c23070 to your computer and use it in GitHub Desktop.
def can_complete_word(word, word_with_blanks):
# Remove all non-alphabetic characters from the word with blanks
word_with_blanks = ''.join(filter(str.isalpha, word_with_blanks))
# Check if the word with blanks is longer than the word
if len(word_with_blanks) > len(word):
return False
# Iterate through each letter in the word with blanks
for i, c in enumerate(word_with_blanks):
# If the current letter is a wildcard, skip to the next letter
if c == '*':
continue
# If the current letter in the word with blanks doesn't match the corresponding letter in the word, return False
if c != word[i]:
return False
# All letters in the word with blanks match their corresponding letters in the word, so the word can complete the word with blanks
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment