Aug-08-2018, 05:24 AM
25 blank lines in my sorted_fruits output list don't know how to get rid of them! Don't know how they got there!here is my script
# This just gives you a feel that something is happening. print('Sorting started') # This defines where the ipnput and output files are fin = open('unsorted_fruits.txt', 'r') fout = open('sorted_fruits.txt', 'w') # This reads the input file Fruits = fin.readlines() # This sorts the input file Fruits.sort() # This for loop writes the fruits to the sorted_fruits list. for fruit in Fruits: fout.write(fruit) # This cloes both files. fin.close() fout.close() # This just lets you know that the sorting is finished. print('Sorting finished')If you run it the output sorted_fruits.txt file has 25 empty lines and then the list starts. This was for home work but i've already turned it in I just want to know if I can get the lines removed? I can't figure it out.