Discuss / Python / 简洁

简洁

Topic source

里奥暮羽

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

def FindMinAndMax(L):

if L != []:

d = (min(L),max(L))

print(d)

if L == []:

print((None,None))

哎呀博雅

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

def FindMinAndMax(L):

    if L != []:

        return(min(L),max(L))

    if L == []:

        return((None,None))

这样不是简单

可是题目是用迭代的方法,不是暂时未学到的方法啊。

如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们称为迭代(Iteration)。

在Python中,迭代是通过for ... in来完成的

凡响skyline

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

总有些自作聪明的


  • 1

Reply