I have a list and need to find two lists in list a
, keeping track of the maximum/minimum, respectively.
Is there a function in some package or numpy
that doesn't require loop? I need to speed up my code as my dataset is huge.
a=[4,2,6,5,2,6,9,7,10,1,2,1]
b=[];c=[];
for i in range(len(a)):
if i==0:
b.append(a[i])
elif a[i]>b[-1]:
b.append(a[i])
for i in range(len(a)):
if i==0:
c.append(a[i])
elif a[i]<c[-1]:
c.append(a[i])
#The output should be a list :
b=[4,6,9,10];c=[4,2,1]