Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
395 B
1
Indexable
Never
from collections import defaultdict

list_of_numbers = [34, 57, 23, 8, 46, 12, 5, 6, 30, 96, 24, 65]
prepared_boxes = defaultdict(list)
box_number = 1
max_size = 100

for number in list_of_numbers:
    if sum(prepared_boxes[f"box-{box_number}"]) + number < max_size:
        prepared_boxes[f"box-{box_number}"].append(number)
    else:
        box_number += 1

print(prepared_boxes)