'batchwise values consumption using python list and dictionary
Hello all i need a little help in finding solution for a datastructure problem using python . I have two datastructures, batches dictionary which contain batch qty for a certain batch and second datastucture so_data is list of orders. Now task is to loop over so_data and consume batchwise quantities in batches on FIFO basis.
batches = {'batch1': 200, 'batch2': 300, 'batch3': 200, 'batch4': 200,
'batch5': 400, 'batch6': 100, 'batch7': 200, 'batch8': 300}
so_data = [50, 50, 50, 10, 340, 10, 40, 20, 150, 330, 50, 150, 20, 50, 30, 100, 60]
def batchwise_consumption(so_data, batches):
print(batches)
for so_qty in so_data:
for bch,bch_qty in batches.items():
if bch_qty > 0:
print('order qty: ', so_qty, ', curr batch qty: ', bch_qty, ', curr batch: ', bch)
if bch_qty >= so_qty:
# order fullfilled by one batch
batches[bch] = bch_qty - so_qty
print('\trem qty: ', batches[bch])
break # break on full filling order
else:
# order fullfilled by partial batches
partial_qty = batches[bch]
batches[bch] = batches[bch] - batches[bch]
rem_so_qty = so_qty-partial_qty
print('\tpartial qty', partial_qty, ', rem so qty', rem_so_qty)
while partial_qty != so_qty:
# make so_qty from multiple batches
break # break on full filling order
print(batches)
batchwise_consumption(so_data, batches)
This problem is part of dataset, following is simulation of batchwise consumption

Any help or some better solution is appreciated. Thanks in advance for helping .
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
