Discuss / Python / 终于作对一题

终于作对一题

Topic source

青年小哲

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

在经过前两次的作业的摧残,终于作对了一个题,。但我知道我的并不是最简单的教程。没有遵从 Less is more. 的原则。

def findMinAndMax(L):
    if len(L) == 0:
        return (None,None)
    elif len(L) == 1:
        x = y = L[0]
        return (x, y)
    else:
        x = max(L)
        y = min(L)
        return (y, x)

selboo

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

做错了,  看题目

请使用迭代查找一个list中最小和最大值,并返回一个tuple:

使用迭代

青年小哲

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

多谢提醒,确实是偷懒直接使用了最大/小值函数来实现的。忘记了迭代的基本概念了。


  • 1

Reply