Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'method.': 0.07; "subject:' ": 0.07; 'subject:help': 0.08; 'logic': 0.09; 'subject:using': 0.09; 'thats': 0.09; 'python': 0.11; 'def': 0.12; "'n'": 0.16; 'argument,': 0.16; 'expecting': 0.16; 'luck!': 0.16; 'received:65.55.116.7': 0.16; 'subject: \n ': 0.16; 'subject:python': 0.16; 'elements': 0.16; 'to:name:python- list@python.org': 0.22; 'received:65.55.116': 0.24; 'satisfying': 0.24; 'sort': 0.25; "i've": 0.25; 'defined': 0.27; 'header:In- Reply-To:1': 0.27; 'skip:- 40': 0.29; 'subject:list': 0.30; 'steven': 0.31; 'fri,': 0.33; 'date:': 0.34; 'but': 0.35; 'done': 0.36; 'method': 0.36; 'similar': 0.36; 'should': 0.36; 'list': 0.37; 'email addr:python.org': 0.37; 'to:addr:python-list': 0.38; 'subject:': 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'email addr:gmail.com': 0.63; 're:': 0.63; 'email name:python-list': 0.65; 'doubts': 0.84; 'numbers:': 0.91; '2013': 0.98 X-TMN: [hW0At2l5gAdGJJ4ojdxiabr9nApVHwve] X-Originating-Email: [carlosnepomuceno@outlook.com] From: Carlos Nepomuceno To: "python-list@python.org" Subject: RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Date: Sat, 25 May 2013 10:53:19 +0300 Importance: Normal In-Reply-To: <74e33270-a79a-4878-a400-8a6cda6637b2@googlegroups.com> References: , <78192328-b31b-49d9-9cd6-ec742c092a29@googlegroups.com>, , <39ac7437-857e-483f-998c-8162c1039933@googlegroups.com>, <51a052d1$0$6599$c3e8da3$5496439d@news.astraweb.com>, <74e33270-a79a-4878-a400-8a6cda6637b2@googlegroups.com> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 25 May 2013 07:53:19.0172 (UTC) FILETIME=[EBE1C040:01CE591C] 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369468467 news.xs4all.nl 15883 [2001:888:2000:d::a6]:37418 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45974 ----------------------------------------=0A= > Date: Fri=2C 24 May 2013 23:05:17 -0700=0A= > Subject: Re: help how to sort a list in order of 'n' in python without us= ing inbuilt functions??=0A= > From: lokeshkoppaka@gmail.com=0A= > To: python-list@python.org=0A= [...]=0A= > ya steven i had done the similar logic but thats not satisfying my profes= sor=0A= > he had given the following constrains=0A= > 1. No in-built functions should be used=0A= > 2. we are expecting a O(n) solution=0A= > 3. Don't use count method=0A= =0A= That's trivial!=0A= =0A= # l is a list of numbers: 0=2C1=2C2=0A= def order_n(l):=0A= =A0=A0=A0 r =3D []=0A= =A0=A0=A0 count =3D [0]*3=0A= =A0=A0=A0 count[2] =3D len(l)=0A= =A0=A0=A0 for i in range(len(l)):=0A= =A0=A0=A0=A0=A0=A0=A0 count[1] +=3D abs((l[i]>0)-1)=0A= =A0=A0=A0=A0=A0=A0=A0 r.insert(count[l[i]]=2C l[i])=0A= =A0=A0=A0 return r=0A= =0A= 'count' is a list I've defined to count the quantity of the elements in the= argument=2C not the method.=0A= =0A= I don't think it needs any explanations=2C but if you have any doubts just = ask. =3B)=0A= =0A= Good luck! =