Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; '"""': 0.05; 'initialize': 0.05; 'lst': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:method': 0.09; 'def': 0.10; "wouldn't": 0.11; 'index': 0.13; '"list': 0.16; "'b'": 0.16; "'b',": 0.16; "'d',": 0.16; "['a',": 0.16; 'dest': 0.16; 'duplicates': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Problem': 0.16; 'then...': 0.16; 'later': 0.16; 'simpler': 0.22; 'elements': 0.23; 'list:': 0.27; 'header:X-Complaints-To:1': 0.28; '"the': 0.29; 'source': 0.29; 'print': 0.32; 'url:home': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'code:': 0.33; 'list': 0.35; 'nov': 0.35; 'list.': 0.35; 'add': 0.36; 'received:org': 0.36; 'subject:with': 0.36; 'charset:us-ascii': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'perform': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'remove': 0.61; 'skip:n 10': 0.63; '...and': 0.84; '10.0,': 0.84; '5.6': 0.84; 'alvaro': 0.84; 'combo': 0.84; 'dennis': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Problem with list.remove() method Date: Tue, 20 Nov 2012 19:08:20 -0500 Organization: > Bestiaria Support Staff < References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-25-251.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353456507 news.xs4all.nl 6926 [2001:888:2000:d::a6]:47103 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33687 On Tue, 20 Nov 2012 05:56:27 -0800 (PST), Alvaro Combo declaimed the following in gmane.comp.python.general: > ...And the code: > > def remove_dup_5_10(): > """ > Remove the duplicates of a given list. The original list MUST be kept. > """ > > # Set the original list > lst = ['a', 1, 10.0, 2, 'd', 'b', 'b', 'b', 1, 2, 'b' ] > > # NEED to create a copy... See dicussion on Problem 5.6 and issue #2 > cpy_lst = list(lst) > Why copy the source list at the start and then... > # Perform an infinite loop... explained later > i=0 # initialize the index > while i != len(cpy_lst): > if cpy_lst.count(cpy_lst[i]) != 1: > cpy_lst.remove(i) ... remove elements from the copy... > else: > i += 1 > > print "The original List: ", lst > print "List with NO duplicates: ", cpy_lst > Wouldn't it be simpler to just add each NON-duplicate of the source to the destination? dest = [] for itm in source: if itm not in dest: dest.append(itm) -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/