Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32526
| Path | csiph.com!usenet.pasdenom.info!aioe.org!rt.uk.eu.org!feed.xsnews.nl!border-2.ams.xsnews.nl!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'desirable.': 0.07; 'int)': 0.09; "('',": 0.16; '(str,': 0.16; '(x,': 0.16; '-1))': 0.16; 'keys:': 0.16; 'oct': 0.16; 'sorts': 0.16; 'wed,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'input': 0.18; 'sort': 0.21; '31,': 0.22; 'tuples': 0.22; 'example': 0.23; 'split': 0.23; 'header:In-Reply- To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'case,': 0.29; 'could': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'sequence': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'construct': 0.84; 'to:name:python': 0.84; 'do:': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=qYgjZynEhx/jX1rXid90pt+8fmmax9szUDisLsSje5k=; b=SOr0su9qPBvnyH3pzdbD8Gj79/4qgqgKfGL6adryQMEkWU8RMivrsJM3+4T/t6saQn +zS3CUyyg2ne/To0Dm8R0reYwBQf7DV3aXP2HFPT+iJcM6iKNHWdoyc0YnmioaSMej01 dAfgLG6XK9ZMzR825j2rOQ23Qe67uXhDrm8MKRo3Z8pToj6kIxl+GnPMwFSwoPnRzixL opkevX2GKz/uI6QvikF9TIa9Umdkx94ZAyXz4jnEh7EAqsw/zpx4aDs3JQVztwyzEdSV FU9ahZpttqMIPfeM+vJmlAoIpJtS9hdZYchE2KrpajRdaUl+pjEUXi98ETcq465CClhP zf6Q== |
| MIME-Version | 1.0 |
| In-Reply-To | <k6rfdu$rgn$1@news.albasani.net> |
| References | <k6rfdu$rgn$1@news.albasani.net> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Wed, 31 Oct 2012 09:44:10 -0600 |
| Subject | Re: sort order for strings of digits |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3121.1351698283.27098.python-list@python.org> (permalink) |
| Lines | 16 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1351698283 news.xs4all.nl 6889 [2001:888:2000:d::a6]:38142 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32526 |
Show key headers only | View raw
On Wed, Oct 31, 2012 at 9:17 AM, djc <djc@kangoo.invalid> wrote:
> The best I can think of is to split the input sequence into two lists, sort
> each and then join them.
In the example you have given they already seem to be split, so you
could just do:
sorted(n, key=int) + sorted(s)
If that's not really the case, then you could construct (str, int)
tuples as sort keys:
sorted(n+s, key=lambda x: ('', int(x)) if x.isdigit() else (x, -1))
Note that the empty string sorts before all numbers here, which may or
may not be desirable.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sort order for strings of digits djc <djc@kangoo.invalid> - 2012-10-31 15:17 +0000
Re: sort order for strings of digits Hans Mulder <hansmu@xs4all.nl> - 2012-10-31 16:31 +0100
Re: sort order for strings of digits Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-31 09:44 -0600
Re: sort order for strings of digits Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-31 14:17 -0400
Re: sort order for strings of digits Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-31 21:33 +0000
Re: sort order for strings of digits Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-31 19:05 -0400
Re: sort order for strings of digits Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-31 23:44 +0000
Re: sort order for strings of digits Chris Angelico <rosuav@gmail.com> - 2012-11-01 11:53 +1100
Re: sort order for strings of digits Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-02 00:27 +0000
Re: sort order for strings of digits Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-31 23:09 +0000
Re: sort order for strings of digits DJC <djc@news.invalid> - 2012-10-31 23:45 +0000
Re: sort order for strings of digits Arnaud Delobelle <arnodel@gmail.com> - 2012-11-01 00:59 +0000
Re: sort order for strings of digits Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-01 00:30 +0000
Re: sort order for strings of digits wxjmfauth@gmail.com - 2012-11-01 01:52 -0700
csiph-web