Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #read in a txt x
  2. #change txt input to list
  3. #take out all punctuations
  4. #split into words
  5. #def that can tell what paragraph each word is in
  6. #puts the words into alphabetical order and prints out what paragrah it was in
  7. #def that prints how often each word comes up into a top 10 list
  8. #top 20 list
  9.  
  10. def open_file(filename): #opens a txt
  11. file_object = open(filename, "r")
  12. return file_object
  13.  
  14. def list_object(file_object):#turns txt into a list+
  15. words = []
  16. for word in file_object:
  17. words.append(word.strip().replace(",", "").replace(".", ""))
  18. return words
  19.  
  20. def main():
  21. try:
  22. filename = input("Enter name of file: ")
  23. file_object = open_file(filename)
  24. words = list_object(file_object)
  25. print(words)
  26. except FileNotFoundError:
  27. print(" File " + filename + " not found!")
  28.  
  29. main ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement