Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #read in a txt x
- #change txt input to list x
- #take out all punctuations x
- #split into words x
- #def that can tell what paragraph each word is in
- #puts the words into alphabetical order and prints out what paragrah it was in
- #def that prints how often each word comes up into a top 10 list
- #top 20 list
- def open_file(filename): #opens a txt
- file_object = open(filename, "r")
- return file_object
- def list_object(file_object):#turns txt into a list
- lists = []
- for word in file_object:
- lists.append(word.replace(",", "").replace(".", ""))
- return lists
- def words_object(lists): #split list into words
- words = []
- for word in lists:
- words.append(word.split())
- return words
- def alphab_object(words): #puts the list into a alphabetical order
- words.sort()
- return words
- def main():
- try:
- filename = input("Enter name of file: ")
- file_object = open_file(filename)
- lists = list_object(file_object)
- words = words_object(lists)
- words = alphab_object(words)
- print(words)
- except FileNotFoundError:
- print(" File " + filename + " not found!")
- main ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement