0
How to remove the maximum item in the list?
1. For example: List = [1, 9, 107, 56, 0, 87] Or 2. For example: List = [6, 9, 109, 1000, 0, 87] In first case is 107, in second 1000 I want to remove the maximum item
3 ответов
+ 6
list = [1, 2, 8, 10, 6, 9]
print(list)
list.remove(max(list))
print(list)
+ 4
#if you want to remove all copies of max
lst = [10, 9, 1, 2, 3, 10, 4, 5, 10]
newlist = [ i for i in lst if i != max(lst) ]
print(newlist)
0
You can find the maximum item with "max()" method and then remove it with "remove()".
For example:
**************************
list = [1, 9, 107, 56, 0, 87]
maximum_item = max(list)
list.remove(maximum_item)
**************************
Now your list is: [1, 9, 56, 0, 87]