def collect self parts sizes items_sizes self calculate_ratio sizes su

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def collect(self, parts, sizes):
items_sizes = self.calculate_ratio(sizes, sum(map(len, parts)))
result = []
atoms = map(list, parts)
for index, size in enumerate(items_sizes):
result.append(''.join(atoms[index][:size]))
del atoms[index][:size]
result = ''.join(result)
while any(atoms):
for x in filter(bool, atoms):
result += x[0]
del x[0]
return result