I have 3 lists of prices:
iexMin = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]
withLimit = [0.649, 1.298, 1.298, 2.538, 2.596, 2.596, 2.560, 2.560, 0.560, 1.682, 1.682, 2.242, 2.242, 2.242, 2.287, 2.592, 2.388, 2.98, 3.29, 3.299]
beyondLimit = [0.66, 2.30134, 2.30155, 2.30171, 2.955, 2.51, 2.519, 2.51, 1.749, 1.749, 1.749, 1.745, 1.749, 1.82208, 1.8993, 1.899, 2.29657, 2.29659, 2.29692, 2.30931]
I am dividing them into 4 groups of 5 elements and after that sorting them in decreasing order to get the minimum first 4 min values from each list and then get the compare all the min value from all the list:
n = 5
a = [iexMin[i:i + n] for i in range(0, len(iexMin), n)]
b = [withLimit[i:i + n] for i in range(0, len(iexMin), n)]
c = [beyondLimit[i:i + n] for i in range(0, len(iexMin), n)]
testList1 = [sorted(block)[:4] for block in a]
testList2 = [sorted(block)[:4] for block in b]
testList3 = [sorted(block)[:4] for block in c]
price1 = [item for t in testList1 for item in t]
price2 = [item for t in testList2 for item in t]
price3 = [item for t in testList3 for item in t]
minRate = [min(price1[i],price2[i],price3[i]) for i in range(len(price1))]
output:
min rate = [0.649, 1.298, 1.298, 2.30171, 0.56, 1.682, 2.51, 2.51, 1.682, 1.749, 1.749, 1.82208, 1.899, 2.29657, 2.29659, 2.29692]
The only problem with this output is that I am not comparing the whole matrix here. As I stated that at the beginning that I am dividing the lists into 4 blocks of 5 elements, so basically I want to compare the whole block at once and the 5 min values from each block. So expected output will look like this:
IEXMin = [[20, 20, 20, 20], [20, 20, 20, 20], [20, 20, 20, 20], [20, 20, 20, 20]]
withinLimit = [[0.649, 1.298, 1.298, 2.538], [0.56, 1.682, 2.56, 2.56], [1.682, 2.242, 2.242, 2.242], [2.388, 2.592, 2.98, 3.29]]
beyondLimit = [[0.66, 2.30134, 2.30155, 2.30171], [1.749, 1.749, 2.51, 2.51], [1.745, 1.749, 1.749, 1.82208], [1.899, 2.29657, 2.29659, 2.29692]]
##Expected Answer##
min rate = [0.649, 0.66, 1.298, 1.298, 0.56, 1.682, 1.749, 1.749, 1.682, 1.745, 1.749, 1.749, 1.899, 2.29657, 2.29659, 2.29692]
So as you can see I actually want to compare the block at a time and get the first 4 min value from each block. Can someone please help?