inserting into a list

Ratko Jagodic rjagodic at gmail.com
Tue Mar 7 10:32:56 EST 2006


from the Library Reference:
s.insert(i, x) same as s[i:i] = [x] (5)

On 3/7/06, John Salerno <johnjsal at nospamgmail.com> wrote:
>
> Let me apologize in advance for what I'm sure is an achingly simple
> question, but I just can't find the answer in either of my Python books.
> I've tried a few tests with the interactive prompt, but they don't work
> either.
>
> All I'm trying to do is insert an item into a list, like so:
>
> L = [1, 2, 4]
>
> and I want to insert the integer 3 into the position L[2], so that the
> list reads [1, 2, 3, 4]
>
> I've tried all kinds of combinations of slicing assignment, but I always
> get:
>
> TypeError: can only assign an iterable
>
> Can someone please embarrass me with the simple answer?  :)
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060307/a048dd26/attachment.html>


More information about the Python-list mailing list