Created
March 24, 2023 12:30
-
-
Save maxandersen/42182eb242b30e43aff53bba44c23070 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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