+ 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
9 odpowiedzi
+ 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 (-:
+ 3
a = [min(a), max(a)]
+ 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
+ 1
Ada min positive not max positive thats why<= or < 0
+ 1
Markus Kaleton Working with a sorted list makes it a trivial exercise.
+ 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)
0
Louis I had the assumption that he is working with a sorted list.
0
Louis it's not much harder if he'd be handling your example
0
I think you are looking for this:
https://code.sololearn.com/cBVB48PeFW73/?ref=app