Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51998

Re: Sort lines in a plain text file alphanumerically

From alex23 <wuwei23@gmail.com>
Newsgroups comp.lang.python
Subject Re: Sort lines in a plain text file alphanumerically
Date 2013-08-06 13:51 +1000
Organization A noiseless patient Spider
Message-ID <ktprfh$lpf$2@dont-email.me> (permalink)
References <520058D7.10105@Gmail.com> <mailman.228.1375758799.1251.python-list@python.org> <ktprbs$lpf$1@dont-email.me>

Show all headers | View raw


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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Sort lines in a plain text file alphanumerically Joshua Landau <joshua@landau.ws> - 2013-08-06 04:12 +0100
  Re: Sort lines in a plain text file alphanumerically alex23 <wuwei23@gmail.com> - 2013-08-06 13:49 +1000
    Re: Sort lines in a plain text file alphanumerically alex23 <wuwei23@gmail.com> - 2013-08-06 13:51 +1000
    Re: Sort lines in a plain text file alphanumerically alex23 <wuwei23@gmail.com> - 2013-08-06 14:33 +1000
    Re: Sort lines in a plain text file alphanumerically Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-08-06 06:40 -0400

csiph-web