返回列表中的最后一项 [英] return the last item in a list
问题描述
我已经google了上面的内容并得到了太多的点击..
我正在寻找一个''简单' '返回列表中最后一项的方法。
我想过
list [len(list)-1 ]
但是我认为会有更优雅的方式。
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.
推荐答案
30 2005年3月10:48:17 -0700,谣言说David Bear
< Da ******** @ asu.edu>可能写的:
On 30 Mar 2005 10:48:17 -0700, rumours say that David Bear
<Da********@asu.edu> might have written:
我已经google了上面的内容并获得了太多的点击量。
我正在寻找一个''容易''返回列表中最后一项的方法。
我想过
列表[len(list)-1]
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.
有。
alist [-1]
您是否阅读过本教程?这在3中引用。非正式的
Python简介" ;.
-
TZOTZIOY,我说英格兰最好。
" ;发送时要严格,接收时要宽容。 (来自RFC1958)
我真的应该在与人交谈时牢记这一点,实际上......
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...
[David Bear]
[David Bear]
我正在寻找一种简单的方式让列表中的最后一项返回。
I''m looking for an ''easy'' way to have the last item in a list returned.
尝试mylist.pop()或者mylist [-1]。
Raymond Hettinger
Try mylist.pop() or mylist[-1].
Raymond Hettinger
Raymond Hettinger写道:
Raymond Hettinger wrote:
我正在寻找一种简单的方式让列表中的最后一项返回。
I''m looking for an ''easy'' way to have the last item in a list returned.
尝试mylist.pop()或mylist [ -1]。
Try mylist.pop() or mylist[-1].
请注意,list.pop还会删除
流程中列表中的最后一个元素。
-
Erik Max Francis&& ma*@alcyone.com && http://www.alcyone.com/max/
美国加利福尼亚州圣何塞市&& 37 20 N 121 53 W&& AIM erikmaxfrancis
承认我必须死,我该怎样生活?
- Michael Novak
Note that list.pop also removes the last element from the list in the
process.
--
Erik Max Francis && ma*@alcyone.com && 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
这篇关于返回列表中的最后一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!