no shift/unshift?

Peter Hansen peter at engcorp.com
Fri Feb 21 15:35:25 EST 2003


"Michael P. Soulier" wrote:
> 
>     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.

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
Alternative ReadLine 1.4 -- Copyright 2001, Chris Gonnerman
>>> l = [1, 2, 3]
>>> dir(l)
['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse',
'sort']
>>> l.append(4)
>>> l.insert(0, 5)
>>> l
[5, 1, 2, 3, 4]
>>> l.pop()
4
>>> l
[5, 1, 2, 3]
>>> l.pop.__doc__
'L.pop([index]) -> item -- remove and return item at index (default last)'
>>> l.pop(0)
5
>>> l
[1, 2, 3]
>>>

Hmm....  ;-)

-Peter




More information about the Python-list mailing list