no shift/unshift?

Inyeol Lee inyeol.lee at siimage.com
Fri Feb 21 21:36:10 CET 2003


On Fri, Feb 21, 2003 at 08:18:03PM +0000, Michael P. Soulier wrote:
>     Hello,
> 
>     I was wondering, is there no built-in way to pull values off and on to a
> list in python? append and pop are find if you are working with the right
> side, but if you need to work with both, having something like shift and
> unshift from perl would be nice. 
>     If I just need to simulate a stack, I'll reverse the list if need be, but
> sometimes I want to manipulate both sides. 

>>> L = range(5)
>>> L 
[0, 1, 2, 3, 4]
>>> L.insert(0, -1)
>>> L
[-1, 0, 1, 2, 3, 4]
>>> L.pop(0)
-1

Inyeol





More information about the Python-list mailing list