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


Groups > comp.lang.python > #35472

Re: Custom alphabetical sort

References <40d108ec-b019-4829-a969-c8ef513866f1@googlegroups.com> <mailman.1257.1356365475.29569.python-list@python.org> <0181c694-7605-4857-8469-baf214c85820@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-12-24 10:29 -0700
Subject Re: Custom alphabetical sort
Newsgroups comp.lang.python
Message-ID <mailman.1260.1356370208.29569.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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

> > >>> ''.join(sorted(random.sample(cs, 20), key=d.get))
> >
> > '5aAàÀåBCçËÉíÎLÖøquùx'
>
> 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=collate)

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.

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


Thread

Custom alphabetical sort Pander Musubi <pander.musubi@gmail.com> - 2012-12-24 07:32 -0800
  Re: Custom alphabetical sort Thomas Bach <thbach@students.uni-mainz.de> - 2012-12-24 17:11 +0100
    Re: Custom alphabetical sort Pander Musubi <pander.musubi@gmail.com> - 2012-12-24 08:34 -0800
      Re: Custom alphabetical sort Ian Kelly <ian.g.kelly@gmail.com> - 2012-12-24 10:29 -0700
    Re: Custom alphabetical sort Pander Musubi <pander.musubi@gmail.com> - 2012-12-24 08:34 -0800
  Re: Custom alphabetical sort wxjmfauth@gmail.com - 2012-12-27 10:17 -0800
    Re: Custom alphabetical sort Terry Reedy <tjreedy@udel.edu> - 2012-12-27 17:17 -0500
    Re: Custom alphabetical sort Ian Kelly <ian.g.kelly@gmail.com> - 2012-12-27 16:17 -0700
      Re: Custom alphabetical sort wxjmfauth@gmail.com - 2012-12-28 02:27 -0800

csiph-web