Python: how to find value in list smaller than target

后端 未结 6 1189
一个人的身影
一个人的身影 2021-01-12 08:51

For example I have a non-ordered list of values [10, 20, 50, 200, 100, 300, 250, 150]

I have this code which returns the next greater value:

def GetN         


        
6条回答
  •  说谎
    说谎 (楼主)
    2021-01-12 09:23

    Let the unordered list be myList:

    answer = max(x for x in myList if x < temp)

提交回复
热议问题