替换python中内置的min函数
我应该编写一个函数 min_in_list(munbers)
,它需要一个列表 数字并返回最小的一个。注意:不允许使用内置函数 min
!
def min_in_list(numbers):
the_smallest = [n for n in numbers if n < n+1]
return the_smallest
怎么了?
I should write a function min_in_list(munbers)
, which takes a list of
numbers and returns the smallest one. NOTE: built-in function min
is NOT allowed!
def min_in_list(numbers):
the_smallest = [n for n in numbers if n < n+1]
return the_smallest
What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须从列表中生成 1 个数字,而不仅仅是另一个列表。这就是
reduce
函数的工作(当然,你可以不使用reduce
来实现它,但以此类推)。You have to produce 1 number from list, not just another list. And this is work for
reduce
function (of course, you can implement it withoutreduce
, but by analogy with it).干得好。这几乎肯定是您能做到的最简单的事情。当你交作业时,你甚至不必给我学分。
Here you go. This is almost certainly about as simple as you could make it. You don't even have to give me credit when you turn the assignment in.
从未经过测试,使用风险自负。
Never been tested, use at your own risk.