0
Can anyone help me please? In a random list how to remove all negative elements coming before min element of a list
3 Antworten
+ 1
import random
a = [random.randint(-9,9) for i in range(20)]
print(a)
print([i for i in a[:a.index(min(a))] if i >=0]+a[a.index(min(a)):])
0
you store min(list) into a variable. then you iterate all numbers in the list with a for loop to check if its the min value and if its not you remove it.
a = [1,2,3,-1,-5,1,2,6]
b = min(a)
while True:
if a[0] != b:
del a[0]
else:
print(a)
break:
0
thanks Louis it worked