[Python-Dev] List insert at index that is well out of range - behaves like append
ethan at stoneleaf.us
Tue Sep 16 00:53:41 CEST 2014
On 09/15/2014 03:46 PM, Mark Lawrence wrote:
> On 15/09/2014 23:29, Mark Shannon wrote:
>> I think this is an OK forum for this question.
It isn't. ;)
>> If someone isn't sure if something is a bug or not, then why not ask
>> here before reporting it on the bug tracker?
The first stop should still be the main Python list, or Python Dev would be inundated with questions about why this or
that doesn't work the same way as <insert other language here>. If the responses from Python list indicate that it is
(or probably is) a bug, then possibly a post here to verify -- but a bug-tracker entry at that point is quite reasonable.
>> This does seem strange behaviour, and the documentation for list.insert
>> gives no clue as to why this behaviour was chosen.
> I assume it's based on the concepts of slicing. From the docs "s.insert(i, x) - inserts x into s at the index given by
> i (same as s[i:i] = [x])". Although shouldn't that read s[i:i+1] = [x] ?
No. If it was `s[i:i+1]` then the ith element would be replaced by the inserted object.
More information about the Python-Dev