sorting list python

Germán Fajardo german.fajardo at
Wed Jan 18 16:23:37 EST 2017

with open('partite.txt', 'r') as r:
    for line in sorted(r):
        print(line, end='')

2017-01-18 15:38 GMT-05:00 Smith <smith at>:

> On 18/01/2017 21:34, MRAB wrote:
>> If you're wondering about the blank lines, it's because the lines end
>> with '\n', which starts a new line, and the print function also starts a
>> new line after printing the string.
>> Try stripping the '\n' off the end of the line read in with the .rstrip
>> method.
> Thank you for your kind cooperation
> --


Germán A. Fajardo G.

More information about the Python-list mailing list