Adding item in front of a list
Thomas Guettler
pan-newsreader at thomas-guettler.de
Wed Apr 9 10:59:36 EDT 2003
On Wed, 09 Apr 2003 14:54:22 +0200, Skip Montanaro wrote:
> Thomas> I think it would be nice if
> Thomas> l=[2, 3, 4]
> Thomas> l.insert(1)
>
> Thomas> would insert in front of the list, as opposed to append()
> which Thomas> adds new elements at the end.
>
> What about
>
> >>> lst = [2,3,4]
> >>> lst.insert(0, 1)
> >>> lst
> [1, 2, 3, 4]
Hi,
insert(0, 1) behaves like insert(-1, 1). It is better, but
insert(1) would be best.
This is not about the functionality, but about the beauty of python.
Would be nice if handling lists like queues and stacks would be a bit
better.
I know it is not important, I just wanted to know if I have overlooked
something and would you think about it.
thomas
--
Thomas Guettler <guettli at thomas-guettler.de>
http://www.thomas-guettler.de
More information about the Python-list
mailing list