Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

python question! please shoe code and steps! thanks! Here is the the information

ID: 3677193 • Letter: P

Question

python question!

please shoe code and steps!

thanks!

Here is the the information from limerick.txt.

Your guy can edit to limerick.txt

A programming genius called Hank
Wrote a system to 'access' his 'bank'
When his memory failed him
They nailed him then jailed him
Now his 'storage' is 'basic' and dank.

Lab Question 3 (Sorting Files): Write a function sortFile (src, dst) that sorts file with name src line by line in lexicographic order and writes the result to file with name dst without modifying src. Place the function in the file 93_yourmacid.py Hints: If f is a file object, list (f) reads the whole file as a list of lines. Use the sort method of lists for sorting and the join method of strings for concatenating a list of strings. For example sorting limerick.txt (from the web site) would result in a file with: A programming genius called Hank Now his 'storage' is 'basic' and dank. They nailed him then jailed him When his memory failed him Wrote a svstem to 'access' his 'bank' Mzote a systen to 'access' his 'bank

Explanation / Answer

def sortFile( src, dst ):
   input_file = open(src, "r")
   # omit empty lines and lines containing only whitespace
   lines = [line for line in input_file if line.strip()]
   input_file.close()
   lines.sort() # sorting the input file
   # now write the output file
   output_file = open(dst, "w")
   for item in lines:
           output_file.write("%s " % item)
   output_file.close()


sortFile("limerick.txt", "output.txt")