Discuss / Python / 因为题目说了是用迭代的,所以就不考虑用内置函数max和min了

因为题目说了是用迭代的,所以就不考虑用内置函数max和min了

Topic source

Nectar

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

    if L == []:

        return (None, None)

    else:

        min,max = L[0],L[0]

        for x in L:

            if min > x:

                min = x

            if max < x:

                max = x

        return (min, max)

Matthew

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

请问这里为什么要让:

min,max = L[0],L[0]

或者:

min=max=L[0] 

呢?

Super-String

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

因为循环的第一步要比较大小,所以要初始化呀


  • 1

Reply