accessing front of a list
Doug Fort
doug.fort at verizon.net
Tue Nov 26 20:15:26 EST 2002
On Wed, 27 Nov 2002 00:50:35 +0000, Simon Bunker wrote:
> This is probably a fairly newbie question - and also because I am
> coming from a Perl background. I was wondering if there is a Python
> equivilant to Perls shift operator?
>
> There seem to be many ways of getting access to the end of an array -
> pop() append() etc but I couldn't find anyting to shift off the front like
> when
> reading in argv.
>
You can pop() from either end of a list. pop(0) gives you the head, pop()
or pop(-1) give you the end.
But when accessing a list from front to rear, I find my self using
constructs like 'for x in l:...' or the functional programming tools
map(), filter(), reduce(), etc.
--
Doug Fort, Programmer
http://www.dougfort.net
More information about the Python-list
mailing list