in python Complete the function read_r_line(fname, ln) to take a filename and a line number and return the contents of that line number from the file as a string. Hint: The code from Files03 will be helpful. Example: read_r_line('myf.txt', 5) will return 'I like peanut'
def read_r_line(fname, ln): result = None f = open(fname, 'r') count = 1 for line in f: if count == ln: result = line.strip() count += 1 f.close() return result
in python Complete the function read_r_line(fname, ln) to take a filename and a line number and...
in python Complete the function search_file(fname, wd) to take a filename and a word. If the the word is found in the file contents, the function should return True, otherwise it should return False.
Complete the Python function read_third_line() so that it takes a filename and returns the third line of the file as a string.
In Python: LoadFile is a function that takes in a string (a filename) and then returns a list. The list is the contents of the file, where each element is a list of data from the file. Here's an example of using this function. The input file had four lines of text. >>> lines = LoadFile("test.txt") >>> print("OUTPUT", lines) OUTPUT ["Hello there", "I am a test file", "please load me in and print me out", "Thanks"]
In python def lambda_1(filename): # Complete this function to read grades from `filename` and find the minimum # student test averages. File has student_name, test1_score, test2_score, # test3_score, test4_score, test5_score. This function must use a lambda # function and use the min() function to find the student with the minimum # test average. The input to the min function should be # a list of lines. Ex. ['student1,33,34,35,36,45', 'student2,33,34,35,36,75'] # input filename # output: (lambda_func, line_with_min_student) -- example (lambda_func, 'student1,33,34,35,36,45')...
5. Write a Python function called readlinesmton that accepts the name of the file (i.e. filename), starting line number i.e. m) and ending line number (i.e. n) as a parameter. The function then returns the contents from line number m to n (m <n). If m < 1 then start from line 1. Similarly, if n > number of lines the file, then stop at the last line in the file. Sample Input: readlinesmton("data.txt",5,7) Sample Input: readlinesmton("data.txt", 0,10)
Complete the Python function read_third_line() to read the third line of the file, my2nd.txt. Return the third line as the output of function read_third_line(). Should start with def read_third_line(fname):
Write a function called char_counter that counts the number of a certain character in a text file. The function takes two input arguments, fname, a char vector of the filename and character, the char it counts in the file. The function returns charnum, the number of characters found. If the file is not found or character is not a valid char, the function return -1. As an example, consider the following run. The file "simple.txt" contains a single line: "This...
Write a Python function makeDict() that takes a filename as a parameter. The file contains DNA sequences in Fasta format, for example: >human ATACA >mouse AAAAAACT The function returns a dictionary of key:value pairs, where the key is the taxon name and the valus is the total number of 'A' and 'T' occurrences. For example, for if the file contains the data from the example above the function should return: {'human':4,'mouse':7}
Write a function called char_counter that counts the number of a certain character in a text file. The function takes two input arguments, fname, a char vector of the filename and character, the char it counts in the file. The function returns charnum, the number of characters found. If the file is not found or character is not a valid char, the function return -1. As an example, consider the following run. The file "simple.txt" contains a single line: "This...
python Write the function getSpamLines(filename) that read the filename text file and look for lines of the form 'SPAM-Confidence: float number'. When you encounter a line that starts with "SPAM-Confidence:" extract the floating-point number on the line. The function returns the count of the lines where the confidence value is greater than 0.8. For example, if 'spam.txt' contains the following lines along with normal text getSpamLines('spam.txt') returns 2. SPAM-Confidence: 0.8945 Mary had a little lamb. SPAM-Confidence: 0.8275 SPAM-Confidence: 0.7507 The...