Source code for Exercises.essentials.basic_loops.inventory.inventory

"""
Assume the warehouse is initially empty.

The string `warehouse_log` is a stream of deliveries to 
and shipments from a warehouse.  Each line represents
a single transaction for a part with the number of
parts delivered or shipped.  It has the form::

    part_id count

If "count" is positive, then it is a delivery to the
warehouse. If it is negative, it is a shipment from
the warehouse.

.. hint::
   You should write a loop that updates a dictionary
   whose keys are part_ids and whose values are the
   current number of items in the warehouse with
   that part_id.
"""

warehouse_log = """ frombicator      10
                    whitzlegidget    5
                    splatzleblock    12
                    frombicator      -3
                    frombicator      20
                    foozalator       40
                    whitzlegidget    -4
                    splatzleblock    -8
                """                            
[docs]def update_inventory (warehouse_log): """ Return a dict conatining the current inventory size for each part_id based on `string` `warehouse_log`. """ inventory_dict = defaultdict(lambda: 0) pass # Your code goes here (several lines, probably) return inventory_dict
if __name__ == '__main__': inventory_dict = update_inventory (warehouse_log) ## Add some code for printing the dictionary