view light8/util.py @ 51:71489bb71528

- Meet Fader. He is going to grow up and be a crossfader some day - Meet Fader. He is going to grow up and be a crossfader some day (tomarrow) - Tkinter -> Tix so we can use ScrolledListBox which has a command - Some improvements to Cue - Cues need to specify their final values - Cues are imported by subs. This should be fixed for style points. - Some other cleanups
author dmcc
date Sun, 07 Jul 2002 15:40:45 +0000
parents 62c47c3a90cb
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