Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #read in a txt x
  2. #change txt input to list x
  3. #take out all punctuations x
  4. #split into words x
  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. lists = []
  16. for word in file_object:
  17. lists.append(word.replace(",", "").replace(".", ""))
  18. return lists
  19.  
  20. def words_object(lists): #split list into words
  21. words = []
  22. for word in lists:
  23. words.extend(word.split())
  24. return words
  25.  
  26. def alphab_object(words): #puts the list into a alphabetical order
  27. words.sort()
  28. return words
  29.  
  30. def wordcount_object(words):
  31.  
  32.  
  33.  
  34.  
  35. def main():
  36. try:
  37. filename = input("Enter name of file: ")
  38. file_object = open_file(filename)
  39. lists = list_object(file_object)
  40. words = words_object(lists)
  41. words = alphab_object(words)
  42. for word in words:
  43. print(word)
  44. except FileNotFoundError:
  45. print(" File " + filename + " not found!")
  46.  
  47. main ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement