Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33662
| 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 | <ramit.prasad@jpmorgan.com> |
| 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" <ramit.prasad@jpmorgan.com> |
| To | Alvaro Combo <alvaro.combo@gmail.com>, "python-list@python.org" <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 | <b610616c-c26d-44e1-84c6-fa922a8e3f75@googlegroups.com> |
| In-Reply-To | <b610616c-c26d-44e1-84c6-fa922a8e3f75@googlegroups.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.98.1353445988.29569.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
Alvaro Combo wrote:
>
> Hi All,
>
> I'm relatively new to Python... but I have found something I cannot explain... and I'm sure you can help me.
>
> I have the following function that serves for removing the duplicates from a list... It's a simple and (almost)
> trivial task.
>
> I'm using WingIDE as editor/debugger and have Python 2.7.3.
>
> When running this I have an error when trying to remove cpy_lst[4]... and ONLY THAT!!! Even in interactive
> mode!!!
>
> Any suggestion is MOST welcome.
>
> Best Regards
>
> ACombo
>
> ...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)
>
> # 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)
> else:
> i += 1
>
> print "The original List: ", lst
> print "List with NO duplicates: ", cpy_lst
>
> return True
> --
Remove looks for the *value* not the *index* of the value.
>>> help([].remove)
Help on built-in function remove:
remove(...)
L.remove(value) -- remove first occurrence of value.
Raises ValueError if the value is not present.
Change ` cpy_lst.remove(i)` to `cpy_lst.remove(cpy_lst[i])`.
~Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Problem with list.remove() method Alvaro Combo <alvaro.combo@gmail.com> - 2012-11-20 05:56 -0800
Re: Problem with list.remove() method Chris Angelico <rosuav@gmail.com> - 2012-11-21 01:14 +1100
Re: Problem with list.remove() method Alvaro Combo <alvaro.combo@gmail.com> - 2012-11-20 06:37 -0800
Re: Problem with list.remove() method Chris Angelico <rosuav@gmail.com> - 2012-11-21 07:48 +1100
Re: Problem with list.remove() method Alvaro Combo <alvaro.combo@gmail.com> - 2012-11-20 06:37 -0800
Re: Problem with list.remove() method Terry Reedy <tjreedy@udel.edu> - 2012-11-20 15:32 -0500
RE: Problem with list.remove() method "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-20 20:47 +0000
Re: Problem with list.remove() method Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-11-20 19:08 -0500
csiph-web