0
|
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
|
45
|
16
|
|
17 def subsetdict(d, dkeys, default=0):
|
|
18 'Subset of dictionary d: only the keys in dkeys'
|
|
19 # print 'd', d, 'dkeys', dkeys
|
|
20 newd = {} # dirty variables!
|
|
21 for k in dkeys:
|
|
22 newd[k] = d.get(k, default)
|
|
23 return newd
|