how to sort and append the list of words to an empty list in python -


I am trying to write a python code that reads a bunch of lines from the text file, and then lines the words Then divides into each word, checks to see if the word is already in the list, if it does not exist, then it adds to it and finally changes the list and finally print the final list is that i Has written so far Fh: line = line for row phname = raw_input ("file name:") fh = open (fname) new = list () word for the word rstrip () = line.split (): If not new in w: final = new.append (w) result = final.sort () print result

but I'm getting the error below. AttributeError: ' NoneType 'object has no attribute' sort ', which is on line 12

Do not know why? Any help?

Thanks Upendra

fname = raw_input ("enter file name : ") With FH: # FH as the use: # to automatically close the file using # = = [] new = [x.rstrip (). Split for x in FH) # Strip and words divided into subtitles for eleven: In new words: # For every word in every novelist # If the last word is not in the last: # If the word is not already in the last Then add the last word. Append (word) final.sort () #sort print final

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -