-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles.py
More file actions
29 lines (22 loc) · 748 Bytes
/
Copy pathfiles.py
File metadata and controls
29 lines (22 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def main():
path = input("Enter a file path: ")
function_key_word = input("Enter a task: ")
file = open(path, 'r')
if function_key_word.lower() == "sort":
list_of_words = list()
for line in file:
for word in line.split():
if word not in list_of_words:
list_of_words.append(word)
list_of_words.sort()
print(list_of_words)
elif function_key_word.lower() == "rev":
for line in file:
print(line[::-1])
elif function_key_word.lower() == "last":
n = int(input("Enter a number"))
for line in (file.readlines()[-n:]):
print(line, end='')
file.close()
if __name__ == "__main__":
main()