Jess L
Jess L

Reputation: 69

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. 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?

Upvotes: 1

Views: 795

Answers (1)

ndmeiri
ndmeiri

Reputation: 5039

Return the list that you just modified (lst).

def minremo(lst):
    lst.sort()
    lst.reverse()
    lst.pop()
    return lst

Upvotes: 3

Related Questions