Python Finding Index of Maximum in List

前端 未结 9 2701
别那么骄傲
别那么骄傲 2021-02-19 01:13
def main():
    a = [2,1,5,234,3,44,7,6,4,5,9,11,12,14,13]
    max = 0
    for number in a:
        if number > max:
            max = number
    print max

if __name         


        
9条回答
  •  忘了有多久
    2021-02-19 02:06

    If you aren't allowed to use the built in index() function, just iterate with an index, instead of using a foreach loop.

    for i in range(len(a)):
        if a[i] > max:
            max = a[i]
            maxIndex = i
    

提交回复
热议问题