Unpacking variable length list returned from function

后端 未结 5 598
鱼传尺愫
鱼传尺愫 2021-01-25 18:44

Ok so I\'m defining a function that takes a variable number of inputs and clamps each of them

def clamp(*args):
    return [ max(min(arg, 0.8), 0.2) for arg in a         


        
5条回答
  •  鱼传尺愫
    2021-01-25 19:13

    def clamp(*args):
        lst = [max(min(arg, 0.8), 0.2) for arg in args]
        if len(lst)==1:
            return lst[0]
        return lst
    

提交回复
热议问题