Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77913
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'insert': 0.05; 'assignment': 0.07; 'method.': 0.07; '[1,': 0.09; 'append': 0.09; 'override': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'behaviour.': 0.16; 'indexerror:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:too': 0.16; 'throw': 0.16; 'demonstrate': 0.16; 'index': 0.16; 'trying': 0.19; 'header:User-Agent:1': 0.23; 'subject:like': 0.24; 'equivalent': 0.26; 'least': 0.26; 'header:X-Complaints- To:1': 0.27; 'errors': 0.30; 'originally': 0.30; 'subject:that': 0.31; 'writes:': 0.31; '(i.e.': 0.33; 'problem': 0.35; 'subject:List': 0.36; 'tech': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'according': 0.40; 'even': 0.60; 'range': 0.61; 'received:217': 0.63; '100': 0.79; '"j"': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | dieter <dieter@handshake.de> |
| Subject | Re: List insert at index that is well out of range - behaves like append that too SILENTLY |
| Date | Tue, 16 Sep 2014 07:58:03 +0200 |
| References | <CACC6tEh0b-iR3ChEsYZftxjSJktzqbknqAeTdpxyHCdS7YRHiQ@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-Gmane-NNTP-Posting-Host | pd9e0b10a.dip0.t-ipconnect.de |
| User-Agent | Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) |
| Cancel-Lock | sha1:qlnFITAQgPzar5YlQ4WOFs/YyjY= |
| 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 | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14041.1410847105.18130.python-list@python.org> (permalink) |
| Lines | 34 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1410847105 news.xs4all.nl 2873 [2001:888:2000:d::a6]:47695 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:77913 |
Show key headers only | View raw
Harish Tech <technews.full@gmail.com> writes: > Let me demonstrate the problem I encountered : > > I had a list > > a = [1, 2, 3] > > when I did > > a.insert(100, 100) > > [1, 2, 3, 100] > > as list was originally of size 4 and I was trying to insert value at index > 100 , it behaved like append instead of throwing any errors as I was trying > to insert in an index that did not even existed . > > > Should it not throw > > IndexError: list assignment index out of range At least the documentation states that what you observe is the intended behaviour. According to the documentation, "a.insert(i, x)" is equivalent to "a[i:i] = x" (i.e. a slice assignment) and if in a slice "a[i:j]" "i" or "j" are larger then "len(a)", then it is replaced by "len(a)". If this is not what you want, derive your own list type and override its "insert" method.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: List insert at index that is well out of range - behaves like append that too SILENTLY dieter <dieter@handshake.de> - 2014-09-16 07:58 +0200
csiph-web