定義求最大最小值的函數 輸入為: ...
定義求最大最小值的函數
# Author:Zhang Yide # coding:utf-8 def min(*args, **kwargs): key = kwargs.get("key", None) if len(args) == 1: args = args[0] return sorted(args, key=key, reverse=False)[0] def max(*args, **kwargs): key = kwargs.get("key", None) if len(args) == 1: args = args[0] return sorted(args, key=key, reverse=True)[0] print(max(3, 2)) print(min(3, 2)) print(max([1, 2, 0, 3, 4])) print(min("hello")) print(max(2.2, 5.6, 5.9, key=int)) print(min([[1, 2], [3, 4], [9, 0]], key=lambda x: x[1]))
輸入為:
3 2 4 e 5.6 [9, 0]