Python - 一些有趣的语句
持续更新...
函数
1、找出一个list中的最小和最大值,并返回一个tuple
def findMinAndMax(L): min = L and L[0] or None max = L and L[0] or None for x in L: min = min > x and x or min max = max < x and x or max return (min, max)
2、利用filter()筛选出回数
def is_palindrome(s): s = str(s) return s == s[::-1] if __name__ == '__main__': output = filter(is_palindrome, range(1, 1000)) print('1~1000:', list(output))