Discuss / Python / 练习打卡-Python教程-高级特性-迭代

练习打卡-Python教程-高级特性-迭代

Topic source

南丁叔叔

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

#先用遍历实现排序,然后取两头的就是最大最小值了。可能是我太笨,思考的难受

def findMinAndMax(L):

    if L==[]:

        return (None,None)

    for x in L[:]:

        for i in L[:]:

            if i>x and L.index(i)<L.index(x):

                L.insert(L.index(x)+1,i)

                L.pop(L.index(i))

            elif i<x and L.index(i)>L.index(x):

                L.insert(L.index(i)+1,x)

                L.pop(L.index(x))

    return (L[0], L[-1])


  • 1

Reply