0

I'm trying to write a piece of code in Python 3 that takes a word and a set of letters and sees if the letters can form the given word. At line 4 I keep getting the TypeError stated in the question, and I don't know why because myLetters is a list, and it's not NoneType.

def formWord(myWord, myLetters):
    myLetters = list(myLetters)
    for wordLetters in myWord:
        if wordLetters in myLetters:
            myLetters = myLetters.remove(wordLetters)
            continue
        elif wordLetters not in myLetters:
            return(False)
        else:
            return(True)
zondo
  • 19,901
  • 8
  • 44
  • 83
JKev
  • 1
  • 1
  • 3
    Change `myLetters = myLetters.remove(wordLetters)` to `myLetters.remove(wordLetters)`. Since `.remove()` returns None, you are assigning `myLetters` to `None`. – zondo Jul 24 '16 at 00:55
  • Thank you! Follow up question - the code works and returns False when the word can't be formed but it doesn't return anything when the word can be formed (it should return true). Any advice? – JKev Jul 24 '16 at 01:15
  • Remove the `else:` line, and remove some of the indentation of the `return True` so that it has the same indentation as the `for wordLetters in myWord:` line. – zondo Jul 24 '16 at 01:17
  • Great, thanks for your help! – JKev Jul 24 '16 at 01:33

0 Answers0