def find_the_best_solution(shipping_request, list, current_solution, best_shipping_solution):
if shipping_request == {}:
return current_solution
for item in shipping_request:
for i in range(0,len(list), 1):
length_of_combination = i+1
combinations = itertools.combinations(list, length_of_combination)
for x in combinations:
if sum(x) >= shipping_request[item]:
if sum(x) > shipping_request[item]:
current_solution['wastage'] += (sum(x) - shipping_request[item])
current_solution['number_of_containers'] += length_of_combination
current_solution['distribution'][item] = x
temp_request = shipping_request
del temp_request[item]
temp_list = list
for y in x:
temp_list.remove(y)
solution = find_the_best_solution(temp_request, temp_list, current_solution, best_shipping_solution)
if solution['wastage'] < best_shipping_solution['wastage']:
best_shipping_solution = solution
elif solution['wastage'] == best_shipping_solution['wastage']:
if solution['number_of_containers'] < best_shipping_solution['number_of_containers']:
best_shipping_solution = solution
return best_shipping_solution
这给出了以下错误-“运行时错误:迭代期间字典大小更改”
我究竟做错了什么?我该怎么做?