In: Computer Science
4. Implement the function read_info_file that consumes a file name (string) as its parameter and returns a list of strings - one element for each line in the file. These lines should have all the whitespace removed from both ends of the line.
a. See the formatting of the individual_info data file. Consider how a file can be read into the program.
In Python language
Program Code Screenshot:
Sample output:
The screenshots are attached below for reference.
Please follow them for proper indentation and output.
Program to copy:
def read_info_file(file):
f=open(file,'r')#open file in read mode
l=list(f.readlines())#read data to list
for i in range(len(l)):
l[i]=l[i][:-1]#remove new line characters from each line
l[i]=l[i].strip()#remove front and end spaces
return l#return list
print(read_info_file("individual_info_data.txt"))#call function
and print returned list
Note:
Please let me know in case of any help needed in the comments section.
Plese upvote my answer. Thank you.