Discuss / Python / 遍历列表比较大小

遍历列表比较大小

Topic source

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

from collections.abc import Iterable

def findMinAndMax(L):

    if isinstance(L, Iterable) and L:

        mix = L[0]

        max = L[0]

        for value in L:

            if mix >= value:

                mix = value

            if max <= value:

                max = value

        return (mix, max)

    else:

        return (None, None)


  • 1

Reply