可能重复:
find the maximum number in a list using a loop在Python上重复列表的长度?
我通过使用循环查找在Python中的列表中的最大数量。为了做到这一点,我需要一个循环遍历整个列表。我可以使用哪个循环遍历整个列表?我是Python的新手。
可能重复:
find the maximum number in a list using a loop在Python上重复列表的长度?
我通过使用循环查找在Python中的列表中的最大数量。为了做到这一点,我需要一个循环遍历整个列表。我可以使用哪个循环遍历整个列表?我是Python的新手。
重复的代码n次,其中n是some_list的长度是这样做了块:
for i in xrange(len(some_list)):
# block of code
或...
i = 0
while i < len(some_list):
# block of code
i = i + 1
你可以通过用一个列表像循环:
for item in lst:
# do something with item
然而,一个更简单的方式来获得在列表中(这似乎是你想要的)最大的产品:
max(lst)
try:
max_ = my_list[0]
except IndexError:
raise ValueError('max on empty sequence?')
for element in my_list[1:]:
if element > max_:
max_ = element
如果我只理解你的问题,我将不得不提供帮助。你可以重复一下吗? – Hyperboreus
查看python [documentation](http://python.org/doc/)。很可能你找到的答案就在那里。 –
来自先前的评论:[whatcha talkin bout willis?](http://www.youtube.com/watch?v=Qw9oX-kZ_9k) – Rubens