+ 3

Help me please! In list a=[a1, a2, ..., an] delete all elements standing between the minimum positive and the maximum negative.

In list a=[a1, a2, ..., an] delete all elements standing between the minimum positive and the maximum negative elements. in Python

2nd Apr 2018, 1:45 PM
Пиров Мустафо
Пиров Мустафо - avatar
9 ответов
+ 5
maxneg = max(list(filter(isneg,a))) minpos = min(list(filter(ispos,a))) b = list(filter(lambda x: x<max or x>min,a)) ispos ,isneg are to be defined I am sure you can do it (-:
2nd Apr 2018, 2:59 PM
Oma Falk
Oma Falk - avatar
+ 3
a = [min(a), max(a)]
2nd Apr 2018, 2:07 PM
Oma Falk
Oma Falk - avatar
+ 2
Not exactly sure if I understand. see if this is what you want. a = [3, -3, 7, -7, 2, 5] min pos : 2 max neg: -3 output is then [3, -3, 2, 5] Is that what you want? If so, here it is https://code.sololearn.com/ciD1EHMBl3NO/?ref=app
2nd Apr 2018, 2:29 PM
Louis
Louis - avatar
+ 1
Ada min positive not max positive thats why<= or < 0
2nd Apr 2018, 2:15 PM
Markus Kaleton
Markus Kaleton - avatar
+ 1
Markus Kaleton Working with a sorted list makes it a trivial exercise.
2nd Apr 2018, 3:07 PM
Louis
Louis - avatar
+ 1
i had to test my previous answer since I remembered that list mutilations during iterations are absolute shait and such my prev answer doesnt even work. i found that the simplest way for me to accompish this is the following: a = [-500, -25, -11, -2, 0, 2, 3, 4, 6] newa = [] def remm(a): for i in a: if i == min(a) or i >= 0: newa.append(i) print(newa) remm(a)
2nd Apr 2018, 3:12 PM
Markus Kaleton
Markus Kaleton - avatar
0
Louis I had the assumption that he is working with a sorted list.
2nd Apr 2018, 2:50 PM
Markus Kaleton
Markus Kaleton - avatar
0
Louis it's not much harder if he'd be handling your example
2nd Apr 2018, 3:23 PM
Markus Kaleton
Markus Kaleton - avatar
0
I think you are looking for this: https://code.sololearn.com/cBVB48PeFW73/?ref=app
2nd Apr 2018, 6:22 PM
Sebastian Keßler
Sebastian Keßler - avatar