view light8/util.py @ 1097:f7618f29bb89

rewrite CurveSet. remove sliders support from curvecalc. curve edits now write quickly to the graph. Ignore-this: d0338e3a21636d992958594e878962e
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 09 Jun 2014 03:05:32 +0000
parents 71489bb71528
children
line wrap: on
line source

def maxes(dicts):
    '''
    ({'a' : 5, 'b' : 9}, {'a' : 10, 'b' : 943})
    '''
    newdict = {}
    for d in dicts:
        for k,v in d.items():
            newdict[k] = max(v, newdict.get(k, 0))
    return newdict

def scaledict(d,scl):
    # scales all values in dict and returns a new dict
    return dict([(k,v*scl) for k,v in d.items()])
    
# class Setting that scales, maxes        

def subsetdict(d, dkeys, default=0):
    """Subset of dictionary d: only the keys in dkeys.  If you plan on omitting
    keys, make sure you like the default."""
    newd = {} # dirty variables!
    for k in dkeys:
        newd[k] = d.get(k, default)
    return newd