[英]Remove minimum from list without min() in Python
I am trying to remove the minimum value from a list of randomly generated numbers without using the minimum function or the remove function. 我试图从一个随机生成的数字列表中删除最小值,而不使用最小函数或删除函数。
I created a function minremo
, but I am unsure of what the return value should be to make it actually work. 我创建了一个函数
minremo
,但我不确定返回值应该是什么让它实际工作。 Thus far, I have a method of removing the minimum. 到目前为止,我有一个删除最小的方法。
def minremo(lst):
lst.sort()
lst.reverse()
lst.pop()
return n
import random
number_list = []
for count in range(10):
number = random.randint(1, 100)
number_list.append(number)
print(number_list)
print(minremo(number_list))
The algorithms to remove the minimum works at file-level scope though: 删除文件级范围的最小工作的算法虽然:
import random
number_list = []
for count in range(10):
number = random.randint(1, 100)
number_list.append(number)
print(number_list)
number_list.sort()
number_list.reverse()
number_list.pop()
print(minremo(number_list))
But it does not work within the function itself. 但它在函数本身内不起作用。 I'm not sure what I should return within the function.
我不确定我应该在函数中返回什么。 What should the return be within this function?
在这个函数中应该返回什么?
Return the list that you just modified ( lst
). 返回刚修改的列表(
lst
)。
def minremo(lst):
lst.sort()
lst.reverse()
lst.pop()
return lst
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.