Question: making a new file by sorting through a textfile . Why when I use the for loop for line in inFile: countryList=[line.rstrip()] I get the

 making a new file by sorting through a textfile . Why

making a new file by sorting through a textfile . Why when I use the for loop

for line in inFile: countryList=[line.rstrip()]

I get the wrong answer, it only writes one line in the new file instead of writing all 29 of them. But when I use the commented out part instead, countryList= [line.rstrip() for line in inFile]

the program works? Aren't they two ways of saying the same thing?

def mainO: inFile - openC Exchrate.txt, "r) #countryList - [line- rstrip() for line in inFile] for line in inFile: countrylist - [line.rstripO1 fon i in range(Len countryList)) countryList[i] = countryList[i]. split(..') countryList.sort(key- Lambda x: x[21) for i in rangeClen(countryList)) )?join(c ountryList[i])+" ' countryListli] outfile - openC" NewExchange.txt w outfile.writelines(countryList outfile.close)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!