How to make weighted queue in Python?

575 views Asked by At

I have list of dictionaries in python and another variable specifying total amount of items to split between first list items.

listA= [ {'name': 'one', 'priority': 3 }, {'name': 'two', 'priority': 6 }, {'name': 'three', 'priority': 1 }  ]

items_to_split= 20

I'm trying to find a way how to assign appropriate amount of items from items_to_split to items from listA based on the priority.Count of items in first list might is various. The higher item priority is the more items from 20 should he get. In this example I'm looking for result like this: (example case is ideal because there is no remain after division)

one: 6 two: 12 three: 2
or
one one one one one one two two two two two two two two two two two two three three
I calculated weight per one priority point - 20/(3+6+1) = 2, and then multiplying the priority of item with that number.
Is there a way how to do it smarted in python using queues or some other method ? thank you

0

There are 0 answers