0
def letters_to_words():
        d = {}
        wordlist = read_file(file)
        for word in wordlist:
                key = tuple(sorted(word))
                val = d.get(key, [])
                d[key] = val.append(word)
        return d

Please note that wordlist is a list of words. I don't understand why the penultimate line of this function raises "AttributeError: 'NoneType' object has no attribute 'append'. Here, val equals the return of the .get method, which shouldn't be returning None since a second argument is provided.

When I add print(type(val)) below the problematic line, every iteration returns except the last, which returns

Note: I've been able to bypass this error by using + instead of the .get method, but would really like to understand this problem.

Thanks for any help in advance.

Alex Yuwen
  • 31
  • 3

0 Answers0