Mercurial > code > home > repos > light9
diff light8/util.py @ 0:45b12307c695
Initial revision
author | drewp |
---|---|
date | Wed, 03 Jul 2002 09:37:57 +0000 |
parents | |
children | f974a462133f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/light8/util.py Wed Jul 03 09:37:57 2002 +0000 @@ -0,0 +1,23 @@ +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