Guest User

Untitled

a guest
Dec 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. fname = input("Enter file name: ")
  2. fh = open(fname)
  3. lst = list()
  4. for line in fh:
  5. line = line.rstrip()
  6. words = line.split()
  7. for word in words:
  8. lst.append(word)
  9. lst.sort()
  10. print(lst)
  11.  
  12. ['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']
  13.  
  14. ['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']
  15.  
  16. for word in words:
  17. if word not in lst:
  18. lst.append(word)
  19.  
  20. fname = input("Enter file name: ")
  21. words = set()
  22. with open(fname) as fh:
  23. for line in fh:
  24. line = line.rstrip()
  25. words.update(set(line.split()))
  26.  
  27. words_list = sorted(list(words))
  28. print(words_list)
Add Comment
Please, Sign In to add comment