Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fname = input("Enter file name: ")
- fh = open(fname)
- lst = list()
- for line in fh:
- line = line.rstrip()
- words = line.split()
- for word in words:
- lst.append(word)
- lst.sort()
- print(lst)
- ['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'the', 'through', 'what', 'window', 'with', 'yonder']
- ['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']
- for word in words:
- if word not in lst:
- lst.append(word)
- fname = input("Enter file name: ")
- words = set()
- with open(fname) as fh:
- for line in fh:
- line = line.rstrip()
- words.update(set(line.split()))
- words_list = sorted(list(words))
- print(words_list)
Add Comment
Please, Sign In to add comment