Sort lines in a plain text file alphanumerically

alex23 wuwei23 at gmail.com
Mon Aug 5 23:51:31 EDT 2013


On 6/08/2013 1:49 PM, alex23 wrote:
> Shouldn't that be:
>
>      with open('/home/collier/pytest/__sort.TXT') as file:
>          data = file.readlines()
>          sorted(data, key=str.casefold, reverse=True)
>
> I'm tempted to say "HINT #5: don't provide a solution without testing it
> first" but that would be pretty obnoxious.

Even more so when I got it wrong myself :)

     data = sorted(file.readlines(), key=str.casefold, reverse=True)

I can never remember which one sorts in place and which doesn't.



More information about the Python-list mailing list