-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythontest_1.py
More file actions
37 lines (24 loc) · 769 Bytes
/
Copy pathpythontest_1.py
File metadata and controls
37 lines (24 loc) · 769 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
30
31
32
33
34
35
36
37
# Importing Libraries
import re
# Function "task_1"
def task_1():
# List that stores word from text file
word_list = []
# Opening file for reading
with open("ReaderFiles/read_file.txt", 'r') as read_file:
for line in read_file:
for word in line.split():
# Extract word using regular expression and adding in list
word = re.findall('[A-Za-z]+', word)
if word:
word_list.append(word[0].capitalize())
read_file.close() # File close
# Opening/Creating file for writing
with open("WriterFiles/write_file_1.txt", 'w') as write_file:
for word in word_list:
# Writing content
write_file.write(word+" ")
write_file.close() # File close
# Main function
if __name__ == "__main__":
task_1()