Adding item in front of a list
Jeff Bernstein
jeffbernstein at yahoo.com
Wed Apr 9 14:26:40 EDT 2003
How about the following?
>>> x = [2,3,4]
>>> x
[2, 3, 4]
>>> x[:0] = [1]
>>> x
[1, 2, 3, 4]
Jeff
Thomas Guettler <pan-newsreader at thomas-guettler.de> wrote in message news:<pan.2003.04.09.14.42.36.965880.811 at thomas-guettler.de>...
> Hi!
>
> I think it would be nice if
> l=[2, 3, 4]
> l.insert(1)
>
> would insert in front of the list, as opposed to append() which adds new
> elements at the end.
>
> l.insert(1) looks better than l.insert(-1,1)
>
> thomas
More information about the Python-list
mailing list