Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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; 'skip:[ 20': 0.03; 'case.': 0.05; 'ascii': 0.07; 'completeness': 0.07; 'subject:How': 0.09; 'ex:': 0.09; 'lst': 0.09; 'received:155': 0.09; 'skip:[ 30': 0.09; 'subject:characters': 0.09; 'ascending': 0.16; 'descending': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'insensitive': 0.16; 'lambda': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:169.70': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'securities,': 0.16; 'sorting.': 0.16; 'sorts': 0.16; 'subject: \n ': 0.16; 'subject:String': 0.16; 'subject:case': 0.16; 'subject:insensitive': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'translation': 0.16; 'string': 0.17; 'wrote:': 0.17; 'examples': 0.18; 'to:name:python- list@python.org': 0.20; 'sort': 0.21; 'to:2**1': 0.23; 'received:169.254': 0.24; 'allows': 0.25; 'pass': 0.25; 'header :In-Reply-To:1': 0.25; 'skip:[ 10': 0.26; 'accuracy': 0.27; 'converting': 0.27; 'instead.': 0.27; 'subject:list': 0.28; 'searches': 0.29; 'received:169': 0.29; 'function': 0.30; 'header:Received:8': 0.30; "skip:' 20": 0.32; 'to:addr:python- list': 0.33; 'done': 0.34; 'list': 0.35; 'compared': 0.35; 'filter': 0.35; 'expected': 0.35; 'table': 0.35; 'but': 0.36; 'characters': 0.36; 'method': 0.36; 'subject:with': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'being': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'skip:n 10': 0.63; 'information,': 0.63; 'url:email': 0.63; 'more': 0.63; 'here': 0.65; 'legal': 0.65; 'results': 0.65; 'subject': 0.66; 'purchase': 0.67; 'applying': 0.69; 'special': 0.73; 'sale': 0.76; 'received:169.254.8': 0.84; 'subject:\t': 0.91; 'subject:Special': 0.93 X-DKIM: OpenDKIM Filter v2.1.3 sf1.jpmchase.com qARILA72032731 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1354040470; bh=0GVx+kz4n7Xfnnv18RxiC454E3zxt5qOAVcDANK4yKE=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=P4IxIyfiogPEZj7d24yIud9pTZ86UhigKvx6Iygiw8UtzeBq8JWlxUyrthy0n3/3C obdL7arYR2w+mlmOGK31Bm5raGKiaeIV9UoKsgGjWRoW0rTpAePdoT62jrtYSQJgSs vWVFvXkXMqONotL//jHeT6F1RcyA/tvNJPhBCmaM= From: "Prasad, Ramit" To: san , "python-list@python.org" Subject: RE: How to sort list of String without considering Special characters and with case insensitive Thread-Topic: How to sort list of String without considering Special characters and with case insensitive Thread-Index: AQHNzMWQzdunZ61NR06rOV9F9gclfpf9+Q6g Date: Tue, 27 Nov 2012 18:21:03 +0000 References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.47] Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes Content-Type: text/plain; charset="us-ascii" 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354041785 news.xs4all.nl 6984 [2001:888:2000:d::a6]:42098 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33978 san wrote:=0D=0A> =0D=0A> Please let me know how to sort the list of String= in either ascending / descending order without considering=0D=0A> special = characters and case=2E=0D=0A> ex: list1=3D['test1_two','testOne','testTwo',= 'test_one']=0D=0A> Applying the list=2Esort /sorted method results in sorte= d list ['test1_two', 'testOne', 'testTwo', 'test_one']=0D=0A> but the witho= ut considering the special characters and case it should be=0D=0A> ['testOn= e','test_one', 'test1_two','testTwo'] OR ['test_one','testOne','testTwo', '= test1_two' ]=0D=0A> =0D=0A> list=2Esort /sorted method sorts based on the a= scii value of the characters but Please let me knwo how do i=0D=0A> achieve= my expected one=0D=0A=0D=0AYou can pass a key function into list=2Esort() = and sorted()=2E This=0D=0Aallows you to customize the sorting=2E In the bel= ow examples=0D=0AI use lambda but you can use a non-lambda function (if you= need=0D=0Amore complexity)=2E=0D=0A=0D=0ACase insensitive searches are oft= en done by converting the =0D=0Astrings being compared into the same case= =2E Here I turned=0D=0Athem all uppercase=2E=0D=0A=0D=0Alst =3D ['test1_two= ', 'testOne', 'testTwo', 'test_one']=0D=0Alst=2Esort(key=3Dlambda x: x=2Eup= per())=0D=0A=0D=0AThis will filter non-alphanumeric characters=2E You may= =0D=0Abe able to create and use a translation table instead=2E=0D=0A=0D=0Al= st=2Esort( key=3Dlambda x: ''=2Ejoin( c=2Eupper() for c in x if c =0D=0Ain = string=2Eletters+string=2Edigits ) )=0D=0A=0D=0A=0D=0A~Ramit=0D=0A=0D=0A=0D= =0A=0D=0AThis email is confidential and subject to important disclaimers an= d=0D=0Aconditions including on offers for the purchase or sale of=0D=0Asecu= rities, accuracy and completeness of information, viruses,=0D=0Aconfidentia= lity, legal privilege, and legal entity disclaimers,=0D=0Aavailable at http= ://www=2Ejpmorgan=2Ecom/pages/disclosures/email=2E