Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'key.': 0.07; "'w',": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'exercise': 0.13; 'result.': 0.15; "'0',": 0.16; "'a',": 0.16; "'b',": 0.16; "'c',": 0.16; "'d',": 0.16; "'e',": 0.16; "'o',": 0.16; "'r',": 0.16; "'z')": 0.16; '...]': 0.16; 'keys.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'scripts.': 0.16; 'sorting': 0.16; 'wrote:': 0.17; 'element': 0.17; 'jan': 0.18; '>>>': 0.18; 'code,': 0.18; 'sort': 0.21; '3.2': 0.22; 'os,': 0.22; 'task': 0.23; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:[ 10': 0.26; 'header:X-Complaints-To:1': 0.28; 'actual': 0.28; 'build,': 0.29; 'lies': 0.29; 'primary': 0.30; 'system,': 0.32; 'german': 0.32; 'to:addr:python-list': 0.33; 'list': 0.35; 'so,': 0.35; 'pm,': 0.35; 'received:org': 0.36; 'data': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'first': 0.61; 'back': 0.62; 'email addr:gmail.com': 0.63; 'french': 0.64; "'2',": 0.84; "'3',": 0.84; 'order:': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Custom alphabetical sort Date: Thu, 27 Dec 2012 17:17:44 -0500 References: <40d108ec-b019-4829-a969-c8ef513866f1@googlegroups.com> <8fc90ea6-4787-4f98-b4b8-c3ae5418d5f0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: <8fc90ea6-4787-4f98-b4b8-c3ae5418d5f0@googlegroups.com> 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: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356646698 news.xs4all.nl 6954 [2001:888:2000:d::a6]:50194 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35659 On 12/27/2012 1:17 PM, wxjmfauth@gmail.com wrote: > Le lundi 24 d=C3=A9cembre 2012 16:32:56 UTC+1, Pander Musubi a =C3=A9cr= it : >> I would like to sort according to this order: >> (' ', '.', '\'', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'= , 'a', 'A', '=C3=A4', '=C3=84', '=C3=A1', '=C3=81', '=C3=A2', '=C3=82', '= =C3=A0', '=C3=80', '=C3=A5', '=C3=85', 'b', 'B', 'c', 'C', '=C3=A7', '=C3= =87', 'd', 'D', 'e', 'E', '=C3=AB', '=C3=8B', '=C3=A9', '=C3=89', '=C3=AA= ', '=C3=8A', '=C3=A8', '=C3=88', 'f', 'F', 'g', 'G', 'h', 'H', 'i', 'I', = '=C3=AF', '=C3=8F', '=C3=AD', '=C3=8D', '=C3=AE', '=C3=8E', '=C3=AC', '=C3= =8C', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', '=C3=B1', 'N', '=C3=91= ', 'o', 'O', '=C3=B6', '=C3=96', '=C3=B3', '=C3=93', '=C3=B4', '=C3=94', = '=C3=B2', '=C3=92', '=C3=B8', '=C3=98', 'p', 'P', 'q', 'Q', 'r', 'R', 's'= , 'S', 't', 'T', 'u', 'U', '=C3=BC', '=C3=9C', '=C3=BA', '=C3=9A', '=C3=BB= ', '=C3=9B', '=C3=B9', '=C3=99', 'v', 'V', 'w', 'W', 'x', 'X', 'y', 'Y', = 'z', 'Z') > One way is to create a list of 2-lists / 2-tuples, like > > [(modified_word_1, word_1), (modified_word_2, word_2), ...] > > and to use the native sorting wich will use the first element > modified_word_2 as primary key. > > The task lies in the creation of the primary keys. > > I did it once for French (seriously) and for German (less > seriously) scripts. (Only as an exercise for fun). > >>> rob =3D ['noduleux', 'no=C3=ABl', 'no=C3=A8se', 'no=C3=A9tique', > ... 'n=C5=93ud', 'noir', 'noir=C3=A2tre'] > >>> z =3D list(rob) > >>> random.shuffle(z) > >>> z > ['noir=C3=A2tre', 'no=C3=A8se', 'noir', 'no=C3=ABl', 'n=C5=93ud', 'no=C3= =A9tique', > 'noduleux'] > >>> zo =3D libfrancais.sortfr(z) > >>> zo > ['noduleux', 'no=C3=ABl', 'no=C3=A8se', 'no=C3=A9tique', 'n=C5=93ud', '= noir', > 'noir=C3=A2tre'] > >>> zo =3D=3D rob > True > PS Py 3.3 warranty: ~30% slower than Py 3.2 Do you have any actual timing data to back up that claim? If so, please give specifics, including build, os, system, timing code,=20 and result. --=20 Terry Jan Reedy