Create list from txt file, sort, and append.
I know I know I can do this with a for loop but I want to do it this way first. I need to create a list from a text file, sort it, then remove any repeated words. I have created a list and sorted it. need to append the list and remove any repeated words and can't figure out how. this is what I have.. ( again yes I know a for loop would likely be cleaner but I want to do it this way first) fname = input("Enter file name: ") fh = open(fname) words = fh.read() words2 = words.rstrip() words3 = words2.split() words3.sort() print(words3) works fine up to this point.. but I know I will need a loop after this point to remove and repeated words. ['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'and', 'and', 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'is', 'is', 'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'sun', 'the', 'the', 'the', 'through', 'what', 'window', 'with', 'yonder']