gpt4 book ai didi

python - 算法(Python): find the smallest number greater than k

转载 作者:太空狗 更新时间:2023-10-29 20:33:05 25 4
gpt4 key购买 nike

我有一个算法角度的问题。我有一个数字列表( float )

1.22,3.2, 4.9,12.3.....and so on

我想找到大于(比方说)4.. 的最小数字所以答案是4.9但除了显而易见的解决方案之外……(遍历列表并跟踪大于 k 的最小数字)执行此操作的“pythonic 方式”是什么。谢谢

最佳答案

min(x for x in my_list if x > 4)

关于python - 算法(Python): find the smallest number greater than k,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8101592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com