Hello , I am trying to implement this function:

def getGuessedWord(theword, wordlist):

    for letter in theword:
        if letter in wordlist:
            print  letter,         

            print  '_',

For example:

theword = 'hi'
wordlist = ['e', 'i', 'o', 's']

must return : _i

but it returns : _iNone

I tried :

  for letter in secretWord:
        if letter in lettersGuessed:
            print  letter,         

            print  '_',
    return letter

but it returns : _ii

theword = 'hi'
wordlist = ['e', 'i', 'o', 's']

def word(n):
    result = []
    for i in tuple(theword):
        if i in wordlist:
    a = ''.join(result)
    return a


From that I get

sayth@linux-g8u9:~/dev> python guess.py 

Thanks for the answer ,but if I don't want to use a list?
Is there a way?

I upadted the answer to convert back to a string.

you need to break up 'hi' to 'h','i' when searching wordlist as 'hi' isn't an element and thats why you get 'none'.

Ok , thanks , but there is no other way with just using 'print' statement?Without using list or tuple at all?

but it returns : _iNone

The "None" is returned by the function so apparently you are calling it with "print function_name()" instead of "function_name". If that does not help then post the entire code including how you call it.

The better practise generally is to return value and print the value, not print inside function. So if you have choise keep the call and make the function to return the value otherwise remove the print from calling it, just do not forget the parenthesis after name


Ok, thanks!I didn't know that!