# Remove the smallest element from the set, s. if the set is empty, it remains empty.

1 vote
878 views

## Problem :

I am not completely expert in Python, but still I am willing to learn good practices while I develop my skills.

I am trying to remove the high and low values from the list of numbers, I know how to do this , but I want to know the better way to do this.

`myrawlist = [1, 4, 0, 3, 2]`
`mysortedlist.sort() #[0, 1, 2, 3, 4]`
`mytrimmedlist = mylist[1:-1] #[1, 2, 3]`

I get the required output, but looking for the better way to do this.

## Solution :

Please find below the another way to do it :

`myrawlist = [1, 4, 0, 3, 2]`
`myrawlist.remove(max(mylist))`
`myrawlist.remove(min(mylist))`

It assumes that the high or low do not have any duplicates in the list.

This will need to do for 2-4 passes through the given list: two to find your max and min values, and another up to 2 to find your values to remove if at all they both happen to be at the end of the list. You could easily reduce this to one by just writing the Python loop to find the required max and min in a single pass and also remember that the index of each so that you can later delete the items by index after the loop.

## Related questions

1 vote
28 views
Problem : I have started learning python a few days ago . So I am doing my practice and I am getting cofused with some little things. Supose I have a list that is: listOfnumbers = [16, 22, 96, 15, 4, 39, 56, 40, 13, 22, 15] So what should I have to do to remove element from list python by index
2 views
Problem: HI KODLOGS: I want to understand how to check if list is eampty in python please explain in detail with examples. For example, if passed the following: a = [] How do I check to see if a is empty?
23 views
Problem: I am a new student in learning python and i am not sure how to check if a list is empty in python. For example, if the following is passed: a = [] How to check if it is empty?
22 views
Problem: Let&rsquo;s say I have a list x = [] in python. How could I check this list is empty or not? Thanks in advance.
1 vote
43 views
Problem: I was trying to check if an element does exist in a list using a pyhton program: primary_list = [ 10, 12, 16, 6, 20, 33 ] a = input("Please enter a number to check if this exists in the list: ") print("Checking if input exists in this list : ") for ... not giving any output that is right. What should I do to fix this and how to check if an element does exist in a list. Thanks in advance.
1 vote
52 views
Problem: I am a begginer in progamming language. I have a qusestion which is: is the empty set an element of every set Please help me to understand this.
23 views
I'm using Python's max function to find the largest integer in a dictionary called count, and the corresponding key (not quite sure if I'm saying it properly; my code probably explains itself better than I'm explaining it). The dictionary count is along the lines of {'a': 100, 'b': 210}, and ... there? If I had {'a': 120, 'b': 120, 'c': 100}, this would only find the first of a and b, not both.
1 vote