Discuss / Python / 使用迭代查找list最大最小值,并返回一个tuple

使用迭代查找list最大最小值,并返回一个tuple

Topic source

南街

#1 Created at ... [Delete] [Delete and Lock User]

def maxmin(L):

    a=L[0]

    b=L[0]

    for x in L:

        if a<x:

            a=x

        if b>x:

            b=x

    return (a,b)#M=(4,6,7,9,2,0,0,1,2,-5,10,99,-1),注意语法,if过后的一行相对前行会有空格


  • 1

Reply