Nov-27-2023, 11:58 PM
I have a sorted list of integers that has about 4000 elements. I'm trying to remove every element that is above 550. I used remove() function for the task but it doesn't seem to work. I also looked into pop, tried it and it doesn't seem to work to because pop I think is for storing single data while also removing it from the original list. I also tried del() function. Since my list is sorted, I could use the del to remove the numbers above 550 just by figuring out from what index the element starts.
Here is my current code using the remove() function:
Here is my current code using the remove() function:
sorted_MD_list = sorted(MD_list) for i in sorted_MD_list: if i > 550: sorted_MD_list.remove(i) print(sorted_MD_list)The result when i print the sorted list is the same list including the values that are above 550.