Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sort(file_path):
- '''
- This function gets a text(str) and print a list with
- all unique words from the str but sorted scendingly.
- '''
- with open(file_path, "r") as file:
- unique_words_list = []
- add_word = ''
- for line in file:
- for word in line.split():
- for letter in word:
- if letter.isalpha:
- add_word += letter
- if add_word not in unique_words_list:
- unique_words_list.append(add_word)
- add_word = '' #reset word to add
- return(unique_words_list.sort())
- def rev(file_path):
- '''
- This function gets a text(str) and print
- every line from the end to the start
- '''
- with open(file_path, "r") as file:
- for line in file:
- return(line[::-1])
- def last(file_path):
- '''
- This function gets a text(str) and a n number from the user
- a prints the last n lines from the str
- every line from the end to the start
- '''
- with open(file_path, "r") as file:
- last = int(input("Enter a number: "))
- lines = file.readlines()
- for i in range(-last, 0):
- return(lines[i])
- file_path = input("Enter a file path: ")
- task = input("Enter a task: ")
- if task == "sort":
- print_me = sort(file_path)
- elif task == "rev":
- print_me = rev(file_path)
- elif task == "last":
- print_me = last(file_path)
- print(print_me)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement