from collections import Iterable
def min_max(L): if not isinstance(L, Iterable): raise TypeError if len(L) == 0: return (None, None) else: a = L[0] b = L[0] for i in L: if i <= a: a = i if i >= b: b = i return (a, b)
Sign in to make a reply
郝宇臻
from collections import Iterable
def min_max(L): if not isinstance(L, Iterable): raise TypeError if len(L) == 0: return (None, None) else: a = L[0]
b = L[0] for i in L: if i <= a: a = i if i >= b: b = i return (a, b)