1

I am write a python code to list all the words in a file.

fname = input("Enter file name: ")
fh = open(fname)
lst = list()
word = list()
for line in fh:
    lst = line.split()
    for w in lst :
        if not w in word :
            word = word.append(w)
word = word.sort()
print(word)

Why does it show

> if not w in word : 
> TypeError: argument of type 'NoneType' is notiterable

Thanks, Michael

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149

1 Answers1

0

You are overwriting word into a None, as word.append(w) returns None (or to be exact, it does not return anything).

Replace word = word.append(w) with word.append(w)

Edit -
Same issue will happen with your word = word.sort(), should replace it with word.sort().

BoobyTrap
  • 967
  • 7
  • 18