In: Computer Science
Write a python program:
There is a file called file 2. File2 is a txt file
and I have written the contents of file 2 below in the exact format
it was in notepad.
# This comment does not make sense
# It is just to make it harder
# The job description starts after this comment, notice that it has
4 lines.
# This job description has 700150 hay system points\\
the incumbent will administer the spending of kindergarden milk
money
and exercise responsibility for making change he or she will
share
responsibility for the task of managing the money with the
assistant
whose skill and expertise shall ensure the successful spending
exercise
from typing import Dict, List, TextIO
def job_description(file2: TextIO) -> List[str]:
Write a program such that the file2 is outputted in such a way so
that the output is like this so that the line containing '#' is not
printed and the non hastag part is written in strings:
The string read from File2.txt is: ['the', 'incumbent',
'will', 'administer', 'the',
'spending', 'of', 'kindergarden', 'milk', 'money', 'and',
'exercise', 'responsibility',
'for', 'making', 'change', 'he', 'or', 'she', 'will', 'share',
'responsibility', 'for',
'the', 'task', 'of', 'managing', 'the', 'money', 'with', 'the',
'assistant', 'whose',
'skill', 'and', 'expertise', 'shall', 'ensure', 'the',
'successful', 'spending',
'exercise']
Raw_code:
from typing import Dict, List, TextIO
# job_description function
def job_description(file2: TextIO)->List[str]:
# reading all lines and storing in data
data:List = file2.readlines()
lst = []
# iterating over each line in data
for line in data:
# if line doesn't contains # character
if "#" not in line:
# splitting the each into words and assining to line
line:List = line.split()
# iterating over through line
for word in line:
# appending each word to lst
lst.append(word)
# returing the lst
return lst
# opening the file2.txt
with open("file2.txt") as infile:
# calling the job_desciption function with infile as
parameter
# printing the return value
print(job_description(infile))