Question

In: Computer Science

4. Implement the function read_info_file that consumes a file name (string) as its parameter and returns...

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

Solutions

Expert Solution

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.


Related Solutions

Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both...
Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both type string. This function checks for the name string in the contacts string and returns that person’s contact information. If the person is not found, the function returns, “name not in contact”. Assume input is always valid. Assume the same name is not repeated in contacts. [You may use split(), range(), len() ONLY and no other built-in function or method] Examples:               contacts = “Frank...
Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both...
Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both type string. This function checks for the name string in the contacts string and returns that person’s contact information. If the person is not found, the function returns, “name not in contact”. Assume input is always valid. Assume the same name is not repeated in contacts. [You may use split(), range(), len() ONLY and no other built-in function or method] Examples:               contacts = “Frank...
Language: Python Function name : sort_by_rating Parameters : file (.csv file), category (string), order (boolean) Returns:...
Language: Python Function name : sort_by_rating Parameters : file (.csv file), category (string), order (boolean) Returns: None Description : You want to see what order the items of a particular category in your file would be in if you sorted them by rating. Given a file, a category of clothing, and an order boolean (True for ascending order, False for descending order), create a function that writes a file called “sorted_items.csv” that includes all of the items in the specified...
Write a parameterized function that takes in a file name as a parameter, reads the file,...
Write a parameterized function that takes in a file name as a parameter, reads the file, calculates the factorial of each number, and displays a formatted output as follows: Factorial of 10 = 3628800 Factorial of 5 = 120
Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
Use the Design Recipe to write a function count_vowels, which consumes a string and returns the...
Use the Design Recipe to write a function count_vowels, which consumes a string and returns the number of vowels in that string. For these purposes, the vowels are a, e, i, o, and u, but never y. Include a Docstring! Note: Count both upper and lowercase vowels! Write 3 assert_equal statements to test your function.
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks if ch is...
Write a function called fnReadInParameters() that takes as parameter(s): • a string indicating the name of...
Write a function called fnReadInParameters() that takes as parameter(s): • a string indicating the name of the parameter le This function should return a dictionary that stores all of the parameter le data of the SIR model in a format that we will describe further below.
On Python Write a function that accepts a relative file path as parameter and returns number...
On Python Write a function that accepts a relative file path as parameter and returns number of non-empty lines in the file. Test your function with the provided sample file studentdata.txt.
A constructor, with a String parameter representing the name of the item.
USE JAVA Item classA constructor, with a String parameter representing the name of the item.A name() method and a toString() method, both of which are identical and which return the name of the item.BadAmountException ClassIt must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it.Inventory classA constructor which takes a String parameter indicating the item type, an int parameter indicating the initial...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT