0

Can anyone help me please? In a random list how to remove all negative elements coming before min element of a list

6th Apr 2018, 11:15 AM
ABDUHAKIM Abdusamadov
ABDUHAKIM Abdusamadov - avatar
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)):])
6th Apr 2018, 11:31 AM
Louis
Louis - avatar
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:
6th Apr 2018, 1:32 PM
Markus Kaleton
Markus Kaleton - avatar
0
thanks Louis it worked
6th Apr 2018, 1:41 PM
ABDUHAKIM Abdusamadov
ABDUHAKIM Abdusamadov - avatar