Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.034 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'def': 0.10; 'dec': 0.15; "skip:' 30": 0.15; '24,': 0.16; 'character:': 0.16; 'instead:': 0.16; 'string': 0.17; 'wrote:': 0.17; '>>>': 0.18; 'email addr:gmail.com>': 0.20; '>>>': 0.22; '>': 0.23; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'words': 0.29; 'skip:& 10': 0.29; 'probably': 0.29; 'error': 0.30; "skip:' 20": 0.32; 'to:addr:python-list': 0.33; 'skip:& 20': 0.33; 'received:google.com': 0.34; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'characters': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'more': 0.63; '8bit%:50': 0.65; 'clearer': 0.84; 'to:name:python': 0.84 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=bzW2MH3ZXtvr9wySVNDQY1os3opvtuNaRoMLZbC632Q=; b=TQgkydP0Qo57LBD+qG4b+MdgW6u3mYDDwC0rfWgT24mmje/BjNBDqGeWjsSHzYALcT oS4wtEDVyez38BOxF43qFUeg7l355TQvc41QMRVlFcia8g2bTKUosmqCyq+odNrbsxZj UfSGpCkax86yY8A7YCLjv5k8fThBoIc60Q1htrJE99DQC84yItXPOTWIyaToyjxyz8Tn Xf/0kQqWUeJ+DP8LJ/bEZ2sQTtiRyR0yN1c8ViIiYmhG2ij26kP0E/vich92DamU/eGN AwDiY9hfEdj9Uh7slthU3i0JuV3JYCwYOgn9BfDAMxaGJfF0OANzzlrHFf7/muPQ49GE qrsA== MIME-Version: 1.0 In-Reply-To: <0181c694-7605-4857-8469-baf214c85820@googlegroups.com> References: <40d108ec-b019-4829-a969-c8ef513866f1@googlegroups.com> <0181c694-7605-4857-8469-baf214c85820@googlegroups.com> From: Ian Kelly Date: Mon, 24 Dec 2012 10:29:29 -0700 Subject: Re: Custom alphabetical sort To: Python Content-Type: multipart/alternative; boundary=047d7b33d650ef45cb04d19c8b70 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356370208 news.xs4all.nl 6905 [2001:888:2000:d::a6]:37221 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35472 --047d7b33d650ef45cb04d19c8b70 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Dec 24, 2012 9:37 AM, "Pander Musubi" wrote: > > >>> ''.join(sorted(random.sample(cs, 20), key=3Dd.get)) > > > > '5aA=E0=C0=E5BC=E7=CB=C9=ED=CEL=D6=F8qu=F9x' > > This doesn't work for words with more than one character: Try this instead: def collate(x): return list(map(d.get, x)) sorted(data, key=3Dcollate) I would also probably change "d.get" to "d.__getitem__" for a clearer error message in the case the string contains characters that it doesn't know how to sort. --047d7b33d650ef45cb04d19c8b70 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On Dec 24, 2012 9:37 AM, "Pander Musubi" <pander.musubi@gmail.com> wr= ote:

> > >>> ''.join(sorted(random.sample(cs, 20), key= =3Dd.get))
> >
> > '5aA=E0=C0=E5BC=E7=CB=C9=ED=CEL=D6=F8qu=F9x'
>
> This doesn't work for words with more than one character:

Try this instead:

def collate(x):
=A0=A0=A0 return list(map(d.get, x))

sorted(data, key=3Dcollate)

I would also probably change "d.g= et" to "d.__getitem__" for a clearer error message in the ca= se the string contains characters that it doesn't know how to sort.

--047d7b33d650ef45cb04d19c8b70--