comparison light8/util.py @ 0:45b12307c695

Initial revision
author drewp
date Wed, 03 Jul 2002 09:37:57 +0000
parents
children f974a462133f
comparison
equal deleted inserted replaced
-1:000000000000 0:45b12307c695
1 def maxes(dicts):
2 '''
3 ({'a' : 5, 'b' : 9}, {'a' : 10, 'b' : 943})
4 '''
5 newdict = {}
6 for d in dicts:
7 for k,v in d.items():
8 newdict[k] = max(v, newdict.get(k, 0))
9 return newdict
10
11 def scaledict(d,scl):
12 # scales all values in dict and returns a new dict
13 return dict([(k,v*scl) for k,v in d.items()])
14
15 # class Setting that scales, maxes
16
17 def subsetdict(d, dkeys, default=0):
18 """Subset of dictionary d: only the keys in dkeys. If you plan on omitting
19 keys, make sure you like the default."""
20 newd = {} # dirty variables!
21 for k in dkeys:
22 newd[k] = d.get(k, default)
23 return newd