Re: return the last item in a list

2005-03-30 Thread Erik Max Francis
Raymond Hettinger wrote:
I'm looking for an 'easy' way to have the last item in a list returned.
Try mylist.pop() or mylist[-1].
Note that list.pop also removes the last element from the list in the 
process.

--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
  Granted that I must die, how shall I live?
  -- Michael Novak
--
http://mail.python.org/mailman/listinfo/python-list


Re: return the last item in a list

2005-03-30 Thread Raymond Hettinger
[David Bear]
> I'm looking for an 'easy' way to have the last item in a list returned.

Try mylist.pop() or mylist[-1].


Raymond Hettinger


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: return the last item in a list

2005-03-30 Thread TZOTZIOY
On 30 Mar 2005 10:48:17 -0700, rumours say that David Bear
<[EMAIL PROTECTED]> might have written:

>I've googled for the above and get way too many hits.. 
>
>I'm looking for an 'easy' way to have the last item in a list returned.
>
>I've thought about
>
>list[len(list)-1]
>
>but thought there would be a more gracefull way.

There is.

alist[-1]

Did you read the tutorial?  This is referenced in "3. An Informal
Introduction to Python".
-- 
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


return the last item in a list

2005-03-30 Thread David Bear

I've googled for the above and get way too many hits.. 

I'm looking for an 'easy' way to have the last item in a list returned.

I've thought about

list[len(list)-1]

but thought there would be a more gracefull way.

-- 
http://mail.python.org/mailman/listinfo/python-list