map a function to a dict of lists
<p>I have a dictionary of lists that resembles the following:</p>

<pre><code>inventory_dict = {'015': [['015 8000’, '8000’, 0, 10, 20], ['015 9005', '9005', 0, 0, 20], ['015 9010','9010', 0, 0, 20]],
    '081’: [['081 5000’, ‘5000’, 30, 10, 20], ['081 7500’, ‘7500’, 0, 10, 20], ['081 8500’,’8500’, 0, 10, 20]],
    ‘124’: [['124 6500’, ‘6500’, 5, 0, 0], ['124 8500’, ‘8500’, 3, 0, 0], ['124 9000’,’9000’, 0, 0, 100]]}
</code></pre>

<p>which I’d like to convert to:</p>

<pre><code>inventory_dict = {'015':['015 9005', '9005', 0, 10, 60],
    '081’: ['081 8500’,’8500’, 30, 30, 60],
    ‘124’: ['124 9000’,’9000’, 8, 0, 100]}
</code></pre>

<p>I need a function to run against (map to) each key/value pair that condenses the multiple value lists into a single list. I’m thinking the function would take 2 size arguments, and the value lists as kwargs? Something like:</p>

<pre><code>def compile_value(size1, size2, **kwargs):

    inv_at_dc = 0
    inv_in_store = 0
    inv_on_order = 0
    target_val = []

    for arg in kwargs:
        inv_at_dc += arg[2]
        inv_in_store += arg[3]
        inv_on_order += arg[4]
        if any([arg[1] == size1, arg[1] == size2]):
            target_val = arg

    if target_val == []:
        target_val = kwargs[-1:]

    target_val[2] = inv_at_dc
    target_val[3] = inv_in_store
    target_val[4] = inv_on_order

    return(target_val)
</code></pre>

<p>and the call would be something like:</p>

<pre><code>compile_value(9005, 9000, [value list 1],[value list 2], etc…)
</code></pre>

<p>will this approach work and if so, <strong>how do I map the function to the original dictionary to return the revised dictionary?</strong></p>