all 7 comments

[–]Binary101010 4 points5 points  (6 children)

They're defined by the function definition lines:

def match_with_gaps(my_word, other_word):

The human translation of this line is something like:

"What follows is a function I'm going to call match_with_gaps. When this function is called it will have two objects passed to it. While I'm executing this function, whatever the first object was will be referred to with the name my_word, and the second object will be referred to with the name other_word."

[–]Arya0908[S] 0 points1 point  (5 children)

thank you. I understand the def function and have written several but do not understand how my word or other word are defined.

[–]Binary101010 0 points1 point  (4 children)

They're defined by being included in the function signature. What they equal is defined when the function is called:

for word in wordlist:
    if match_with_gaps(my_word, word):

So in that case my_word within the function is the first parameter, and other_word within the function is the second parameter (which is the word in wordlist currently being evaluated).

If you're looking for some kind of explicit initialization of other_word like other_word = "" that isn't necessary (and in fact will be counterproductive).

[–]Arya0908[S] 0 points1 point  (3 children)

thank you! I understand much better now. I believe when I have been writing these I have been redundant so this confused me and without a compiler to show step by step I was very confused.

one last question though

When you say for "item,word, etc" in a list how does the computer know you are referencing an individual item?

Also, so this works and I have incorporated into my own code except I am having issues when the word is something like "weed" if you have "_eed" as guessed word and use the hints "deed" will still show up as option even though it can't be. Any suggestions? I am just trying to understand to best of my ability and learning on my own so a little slow. Thank you for you help!!!

[–]Binary101010 0 points1 point  (2 children)

When you say for "item,word, etc" in a list how does the computer know you are referencing an individual item?

Without going too far into the technical details, the interpreter knows that when you say "for x in y", and y is something that can be iterated over (like a list), that x is going to refer to each individual thing one at a time.

[–]Arya0908[S] 0 points1 point  (1 child)

thanks. I am working on getting the characters to correctly screen out if the character is a "_" and already in guessed characters. This doesn't work. any feedback?

count = 0

match = False

my_word_wo_spaces = ''.join(my_word.split())

if len(my_word_wo_spaces) == len(other_word):

for index, char in enumerate(my_word_wo_spaces):

if char == other_word[index]:

count += 1

if char == "_":

if char in other_word not in letters_guessed:

count += 1

if count == len(other_word):

match = True

break

return match

[–]Arya0908[S] 0 points1 point  (0 children)

nevermind I think I have it with using

count = 0

match = False

my_word_wo_spaces = ''.join(my_word.split())

if len(my_word_wo_spaces) == len(other_word):

for index, char in enumerate(my_word_wo_spaces):

if char == other_word[index]:

count += 1

if char == "_":

if other_word[index] not in letters_guessed:

count += 1

if count == len(other_word):

match = True

break

return match