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

12th Nov 2019, 12:33 PM
Марсель Халимов
3 Réponses
+ 6
list = [1, 2, 8, 10, 6, 9] print(list) list.remove(max(list)) print(list)
12th Nov 2019, 12:57 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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)
12th Nov 2019, 6:25 PM
Louis
Louis - avatar
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]
14th Nov 2019, 6:13 AM
Mehran sanea
Mehran sanea - avatar