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.
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")
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.