return the last item in a list

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Wed Mar 30 12:54:28 EST 2005


On 30 Mar 2005 10:48:17 -0700, rumours say that David Bear
<David.Bear at asu.edu> 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...



More information about the Python-list mailing list