I have two lists of the same length, one containing integers and one floats. I want to assign every float number to an integer number - relatively.
By relative, I mean:
- higher integer numbers are supposed to have a higher chance to receive a low float number
- lower integer numbers are supposed to have a lower chance to receive a low float number
For assigning it's enough to append the float numbers to a result array, so that integers[index] matches the assigned result[index].
Since I'm talking about chances, I cannot simply order one list descending and one list ascending and match them.
I'm not quite sure how to approach my problem. I'm looking for some functions/modules I haven't heard of - or as always preferred: pure python build in solutions :)
#INDICES: 0 1 2 3 4 5 6 7 8 9
integers = [5, 5, 2, 4, 3, 1, 4, 5, 2, 3 ]
floats = [0.1, 0.2, 0.3, 0.3, 0.3, 0.7, 0.6, 0.8, 0.5, 0.5]
#possible result (could be different):
result = [0.2, 0.3, 0.3, 0.5, 0.7, 0.8, 0.6, 0.1, 0.3, 0.5]
#the result values are assigned to the integers at the same index
As you can see, in the result example, the result[9]==0.5 is assigned to integers[9]==3, while result[6]==0.6 is assigned to integers[6]==4. Which is an exception to the rest of the list, since in general higher floats were assigned to lower integers.