Can anyone help me please? In a random list how to remove all negative elements coming before min element of a list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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

5th Apr 2018, 9:43 AM
ABDUHAKIM Abdusamadov
ABDUHAKIM Abdusamadov - avatar
8 Answers
0
say the list was l = [1,-6,3,78,-4] you could do for i in l: if i < 0: l.remove(i) print (l)
5th Apr 2018, 9:50 AM
Obbu
Obbu - avatar
0
it deletes all negative elements but I want to delete negative elements coming before min(smallest) element
5th Apr 2018, 9:52 AM
ABDUHAKIM Abdusamadov
ABDUHAKIM Abdusamadov - avatar
0
but if you are taking the smallest element theres no element smaller...
5th Apr 2018, 9:53 AM
Obbu
Obbu - avatar
0
thats what I mean.... if there is delete it else let it be
5th Apr 2018, 9:54 AM
ABDUHAKIM Abdusamadov
ABDUHAKIM Abdusamadov - avatar
0
but you could edit it so its if i < m where m is the min number you define
5th Apr 2018, 9:54 AM
Obbu
Obbu - avatar
0
oh good idea
5th Apr 2018, 9:55 AM
ABDUHAKIM Abdusamadov
ABDUHAKIM Abdusamadov - avatar
0
i got confused because you used the function min() in your scentence and that takes the smallest number in a list
5th Apr 2018, 10:04 AM
Obbu
Obbu - avatar
0
i mean if we have: [10, -3, -4, -6] output: [10, -6] but if we have [10, -6, -3, -4] then do nothing
5th Apr 2018, 10:16 AM
ABDUHAKIM Abdusamadov
ABDUHAKIM Abdusamadov - avatar