hello
i really dont know how even should i ask this it was hard for me and tried multiple ways but couldnt figure it out.
i have 2 dicts lets say:
buy = { 99 : 10, 100 : 9, 102 : 12, 103 : 15}
sell = {101 : 12 , 100.5 : 13, 99 : 14, 98 : 18}
keys are prices and values are quantities so i want to buy cheap and sell expensive.
but quantity have a limitation here .
i know what i should looking for its something like this in step by step.
step1:
buy = {100 : 9, 102 : 12, 103 : 15}
sell = {101 : 2 , 100.5 : 13, 99 : 14, 98 : 18}
step2:
buy = {100 : 7, 102 : 12, 103 : 15}
sell = {100.5 : 13, 99 : 14, 98 : 18}
step3:
buy = {102 : 12, 103 : 15}
sell = {100.5 : 6, 99 : 14, 98 : 18}
here there isnt any thing for me to buy cheap and sell expensive
can guide me what should i do
thanks a lot
What I have tried:
buy_p = []
buy_q = []
sell_p = []
sell_q = []
for i in range(len(buy_p)):
for j in range(len(buy_p)):
if buy_p[i] < sell_p[j]:
if buy_q[i] > sell_q[j]:
buy_q[i] = abs(buy_q[i]-sell_q[j])
else:
sell_q[i] = abs(buy_q[i]-sell_q[j])
this one was the closest one but it not obeying the steps