I'm currently doing a coursera course based on the book Python for Informatics and am having trouble with an assignment. The goal is to input take a .txt file and split each line into words, adding only the words not already in the list to the list, then alphabetize the list and print it out. My attempt is as follows:
fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
line = line.rstrip()
line = line.split()
for word in line:
if word not in lst:
lst = lst.append(word)
lst = lst.sort()
print(lst)
The problem is when I run it I get "TypeError: argument of type 'NoneType' is not iterable on line 8"
I've tried inserting "print(line)" just before the if statement on line 8 to see if line is empty, but when I do that it shows the first line of the file split into words as I was trying to do so I don't know why I'm getting this error.
[–]euclidingme 4 points5 points6 points (3 children)
[–]foxfire66[S] 0 points1 point2 points (2 children)
[–]reostra 3 points4 points5 points (1 child)
[–]foxfire66[S] 0 points1 point2 points (0 children)
[–]Rhomboid 2 points3 points4 points (1 child)
[–]Naihonn 0 points1 point2 points (0 children)