简体   繁体   English

在Python中没有min()的情况下从列表中删除最小值

[英]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.

相关问题 从列表中删除最大值和最小值而不复制列表 - remove max and min from list without copying list 从 python 整数列表中删除最大值和最小值 - Remove Max and Min values from python list of integers 如何在不使用python中的min函数的同时使用while循环从列表中查找最小值 - How to find minimum value from a list using while loop at the same time not using min function in python 在 Python 子列表中查找最小值索引 - min() 返回列表中最小值的索引 - Find index of minimum value in a Python sublist - min() returns index of minimum value in list Python:如何连续删除列表的最小值并将其添加到另一个列表? - Python: How to continuously remove the minimum of a list and add it to another list? 如何在不使用控制台的内置函数的情况下在Python中的整数列表中查找最小值和最大值 - How to find minimum and maximum among a list of integers in Python without using built-in functions from console 列表中的最小和最大总和 Python - Minimum and maximum sums from a list Python 如何从python中的列表中删除json字符串而不会丢失数据 - How to remove a json string from list in python without losing data python从列表中删除元素而不更改其他元素的索引 - python remove element from list without changing index of other elements 如何从python列表中删除没有元音的单词 - How to remove words without vowels from a list in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM