Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.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; 'else:': 0.03; '"""': 0.05; 'initialize': 0.05; 'completeness': 0.07; 'raises': 0.07; 'welcome.': 0.07; 'python': 0.09; '*value*': 0.09; 'list...': 0.09; 'lst': 0.09; 'received:155': 0.09; 'subject:method': 0.09; 'valueerror': 0.09; 'def': 0.10; 'index': 0.13; 'value.': 0.15; '"list': 0.16; "'b'": 0.16; "'b',": 0.16; "'d',": 0.16; '*index*': 0.16; "['a',": 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'duplicates': 0.16; 'from:addr:jpmorgan.com': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:159.53.110': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'securities,': 0.16; 'subject:Problem': 0.16; 'task.': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wingide': 0.16; 'later': 0.16; 'wrote:': 0.17; 'skip:` 20': 0.17; '>>>': 0.18; 'to:name:python-list@python.org': 0.20; 'all,': 0.21; 'trying': 0.21; 'to:2**1': 0.23; 'received:169.254': 0.24; 'header:In-Reply- To:1': 0.25; 'looks': 0.26; 'accuracy': 0.27; 'list:': 0.27; 'received:169': 0.29; '"the': 0.29; "i'm": 0.29; 'function': 0.30; 'error': 0.30; 'header:Received:8': 0.30; 'suggestion': 0.32; 'running': 0.32; 'print': 0.32; 'problem': 0.33; 'to:addr:python- list': 0.33; 'code:': 0.33; 'list': 0.35; 'built-in': 0.35; 'something': 0.35; 'list.': 0.35; 'but': 0.36; 'subject:with': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'perform': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'most': 0.61; 'remove': 0.61; 'first': 0.61; 'relatively': 0.62; 'information,': 0.63; 'url:email': 0.63; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'present.': 0.71; 'sale': 0.76; '...and': 0.84; '10.0,': 0.84; '5.6': 0.84; 'alvaro': 0.84; 'combo': 0.84; 'received:169.254.8': 0.84; 'remove:': 0.84 X-DKIM: OpenDKIM Filter v2.1.3 sj1.jpmchase.com qAKKlrFE010018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1353444473; bh=AJIf+bE6+QnCFhN8TqyP/ighsU/Ja1wE2OG0BzlK8lE=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=aGj8MOHGvDAiboc5Xo7o6zRvSFQxL1VGZGQ6OKb1FXgB9uwLQordS+cpnKDrqabQ2 68H1iUfoufUthyR1F7JCpt0Q8M1URRkLWW8i/jABmDp+KbjJIVyjXcauryDRfSauSD UA91YX90Benlv6OVTQZ93O4abAA0X5r8ILwmFoOo= From: "Prasad, Ramit" To: Alvaro Combo , "python-list@python.org" Subject: RE: Problem with list.remove() method Thread-Topic: Problem with list.remove() method Thread-Index: AQHNxydfzau+VC2ubUGslK52VfrwopfzMJYA Date: Tue, 20 Nov 2012 20:47:47 +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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353445989 news.xs4all.nl 6960 [2001:888:2000:d::a6]:51516 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33662 Alvaro Combo wrote:=0D=0A> =0D=0A> Hi All,=0D=0A> =0D=0A> I'm relatively ne= w to Python=2E=2E=2E but I have found something I cannot explain=2E=2E=2E a= nd I'm sure you can help me=2E=0D=0A> =0D=0A> I have the following functio= n that serves for removing the duplicates from a list=2E=2E=2E It's a simpl= e and (almost)=0D=0A> trivial task=2E=0D=0A> =0D=0A> I'm using WingIDE as e= ditor/debugger and have Python 2=2E7=2E3=2E=0D=0A> =0D=0A> When running thi= s I have an error when trying to remove cpy_lst[4]=2E=2E=2E and ONLY THAT!!= ! Even in interactive=0D=0A> mode!!!=0D=0A> =0D=0A> Any suggestion is MOST = welcome=2E=0D=0A> =0D=0A> Best Regards=0D=0A> =0D=0A> ACombo=0D=0A> =0D=0A>= =2E=2E=2EAnd the code:=0D=0A> =0D=0A> def remove_dup_5_10():=0D=0A> ""= "=0D=0A> Remove the duplicates of a given list=2E The original list MUS= T be kept=2E=0D=0A> """=0D=0A> =0D=0A> # Set the original list=0D= =0A> lst =3D ['a', 1, 10=2E0, 2, 'd', 'b', 'b', 'b', 1, 2, 'b' ]=0D=0A>= =0D=0A> # NEED to create a copy=2E=2E=2E See dicussion on Problem 5=2E= 6 and issue #2=0D=0A> cpy_lst =3D list(lst)=0D=0A> =0D=0A> # Perfor= m an infinite loop=2E=2E=2E explained later=0D=0A> i=3D0 # initialize t= he index=0D=0A> while i !=3D len(cpy_lst):=0D=0A> if cpy_lst=2E= count(cpy_lst[i]) !=3D 1:=0D=0A> cpy_lst=2Eremove(i)=0D=0A> = else:=0D=0A> i +=3D 1=0D=0A> =0D=0A> print "The origin= al List: ", lst=0D=0A> print "List with NO duplicates: ", cpy_lst=0D=0A= > =0D=0A> return True=0D=0A> --=0D=0A=0D=0ARemove looks for the *value*= not the *index* of the value=2E=0D=0A=0D=0A>>> help([]=2Eremove)=0D=0AHelp= on built-in function remove:=0D=0A=0D=0Aremove(=2E=2E=2E)=0D=0A L=2Erem= ove(value) -- remove first occurrence of value=2E=0D=0A Raises ValueErro= r if the value is not present=2E=0D=0A=0D=0AChange ` cpy_lst=2Eremove(i)` t= o `cpy_lst=2Eremove(cpy_lst[i])`=2E=0D=0A=0D=0A~Ramit=0D=0A=0D=0A=0D=0A=0D= =0AThis email is confidential and subject to important disclaimers and=0D= =0Aconditions including on offers for the purchase or sale of=0D=0Asecuriti= es, accuracy and completeness of information, viruses,=0D=0Aconfidentiality= , legal privilege, and legal entity disclaimers,=0D=0Aavailable at http://w= ww=2Ejpmorgan=2Ecom/pages/disclosures/email=2E