Here is my code. Assume I have this:
weights = [0.3,0.1,0.2,0.4]
temp_list = [None,1,None,None]
What I want is if the value is None, shift the weights to the highest weight. For example, The first value of temp_list is None, so I want the weight shifted to the highest weight in weights (in this case 0.4) and therefore get 0.7
[0.0,0.1,0.2,0.7] <- First element is None; add to highest weight to get (0.3+0.4 = 0.7)
[0.0,0.1,0.2,0.7] <- Second element has value; no change
[0.0,0.1,0.0,0.9] <- Third element is None; add to highest weight to get 0.9
[0.0,1.0,0.0,0.0] <-- final output; therefore this weight is 1.0 for the second element since everywhere else is None.
Here is my attempt:
for idx, element in enumerate(temp_list):
if element == None:
# do something about this
max_index = weights.index(max(weights))
weights[max_index] = weights[idx] + weights[max_index]
#set value to 0
weights[idx] = 0.0
print(weights)
My question is how do I find the highest weight number in the list and add my current weight to it? What if I am trying to look for the second or third highest weight number? Or is there a better way to approach this kind of problem?