Lets say I have the following dictionary:
d = {'key1': 3, 'key2': 7, 'key3': 8, 'key4': 10, 'key5': 15, 'key6': 22}
How do I convert it to a list of lists consisting of keys, where the sum of dictionary values corresponding to each sublist's keys does not exceed 20 unless a single value is greater than 20 (d['key6'] here)?
So the expected result in this case would be:
list_of_dict = [['key1', 'key2', 'key3'], ['key4'], ['key5'], ['key6']]
or
list_of_dict = [['key1', 'key2'], ['key3', 'key4'], ['key5'], ['key6']]
The order is not important and there should be as few sublists as possible (i.e [['key1'], ['key2'], ['key3'], ['key4'], ['key5'], ['key6']] is not acceptable).