I am using Python Unittest to run the test-cases it generates nose.xml report which I have parsed and created dictionary like:
{'abc_1': {'duration': 788, 'processed': 0}, 'abc_2': {'duration': 632, 'processed': 0}, 'abc_3': {'duration': 2652, 'processed': 0}, 'abc_4': {'duration': 454, 'processed': 0}, 'abc_5': {'duration': 21, 'processed': 0}, 'abc_6': {'duration': 15, 'processed': 0}, 'abc_7': {'duration': 1200, 'processed': 0}, 'abc_8': {'duration': 8243, 'processed': 0}, 'abc_9': {'duration': 34, 'processed': 0}, 'abc_10': {'duration': 10829, 'processed': 0}, 'abc_11': {'duration': 3879, 'processed': 0}, 'abc_12': {'duration': 121, 'processed': 0}, 'abc_13': {'duration': 684, 'processed': 0}, 'abc_14': {'duration': 1500, 'processed': 0}, 'abc_15': {'duration': 1517, 'processed': 0}, 'abc_16': {'duration': 186, 'processed': 0}, 'abc_17': {'duration': 2033, 'processed': 0}, 'abc_18': {'duration': 1243, 'processed': 0}}
Here, abc_* is script name and duration is total time taken by that particular script for execution. ( ex:- abc_18 took total 1243 seconds to run).
Now, I want to divide all scripts in 4 ( or 5 or 6 or dynamically ) different groups based on time (duration), such a way that all group has equal time.
Like:
Grp1 - abc_18,abc_1,abc_4
Grp2 - abc_17,abc_10,abc_11
Grp3 - abc_2,abc_3
Does python has any algorithm to do this operation?
pythonic solution given in the How to understand the dynamic programming solution in linear partitioning? is working but not sure how can I apply with my list as I am very new to python: my_list = [('abc_1', 15), ('abc_2', 21), ('abc_3', 34), ('abc_4', 121), ('abc_5', 186), ('abc_6', 332), ('abc_7', 454), ('abc_8', 456), ('abc_9', 632), ('abc_10', 684), ('abc_11', 1200), ('abc_12', 1243), ('abc_13', 1500), ('abc_14', 1517), ('abc_15', 2033), ('abc_16', 2652), ('abc_17', 3879), ('abc_18', 8243), ('abc_19', 10829)]
If anybody can help me to re-write that code then it will be great help.