ranges 0-1 50 0-1000 20 0-50 0-10 10 0-15 15 0-20 5-2 50 0-1000 20 0-5

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
ranges = {
'1.0-1.1': {'50.0-1000.0': '0', '20.0-50.0': '0', '0.0-10.0': '0', '10.0-15.0': '0', '15.0-20.0': '0'},
'1.5-2.0': {'50.0-1000.0': '0', '20.0-50.0': '0', '0.0-10.0': '0', '10.0-15.0': '0', '15.0-20.0': '0'},
'0.0-1.0': {'50.0-1000.0': '0', '20.0-50.0': '0', '0.0-10.0': '0', '10.0-15.0': '0', '15.0-20.0': '0'},
'1.0-1.5': {'50.0-1000.0': '0', '20.0-50.0': '0', '0.0-10.0': '0', '10.0-15.0': '0', '15.0-20.0': '0'}
}
results = [{'count': 0, 'amount': '50.0-1000.0', 'odd': '1.0-1.1'},
{'count': 0, 'amount': '20.0-50.0', 'odd': '1.0-1.1'},
{'count': 0, 'amount': '0.0-10.0', 'odd': '1.0-1.1'},
{'count': 0, 'amount': '10.0-15.0', 'odd': '1.0-1.1'},
{'count': 0, 'amount': '15.0-20.0', 'odd': '1.0-1.1'},
{'count': 8, 'amount': '50.0-1000.0', 'odd': '1.5-2.0'},
{'count': 14, 'amount': '20.0-50.0', 'odd': '1.5-2.0'},
{'count': 41, 'amount': '0.0-10.0', 'odd': '1.5-2.0'},
{'count': 20, 'amount': '10.0-15.0', 'odd': '1.5-2.0'},
{'count': 3, 'amount': '15.0-20.0', 'odd': '1.5-2.0'},
{'count': 0, 'amount': '50.0-1000.0', 'odd': '0.0-1.0'},
{'count': 0, 'amount': '20.0-50.0', 'odd': '0.0-1.0'},
{'count': 0, 'amount': '0.0-10.0', 'odd': '0.0-1.0'},
{'count': 0, 'amount': '10.0-15.0', 'odd': '0.0-1.0'},
{'count': 0, 'amount': '15.0-20.0', 'odd': '0.0-1.0'},
{'count': 24, 'amount': '50.0-1000.0', 'odd': '1.0-1.5'},
{'count': 10, 'amount': '20.0-50.0', 'odd': '1.0-1.5'},
{'count': 33, 'amount': '0.0-10.0', 'odd': '1.0-1.5'},
{'count': 22, 'amount': '10.0-15.0', 'odd': '1.0-1.5'},
{'count': 5, 'amount': '15.0-20.0', 'odd': '1.0-1.5'}]
def add_to_empty(results, ranges):
for odd in ranges:
in_range = filter(lambda r, odd=odd: ( odd == r['odd'] ), results)
for ir in in_range:
ranges[odd][ir['amount']] = ir['count']
return ranges
print add_to_empty(results, ranges)
"""
возвращает всё правильно, если вынести всё в отдельный файл и подать перменные в ручную
{'1.0-1.1': {'20.0-50.0': 0, '0.0-10.0': 0, '10.0-15.0': 0, '50.0-1000.0': 0, '15.0-20.0': 0},
'1.5-2.0': {'20.0-50.0': 14, '0.0-10.0': 41, '10.0-15.0': 20, '50.0-1000.0': 8, '15.0-20.0': 3},
'0.0-1.0': {'20.0-50.0': 0, '0.0-10.0': 0, '10.0-15.0': 0, '50.0-1000.0': 0, '15.0-20.0': 0},
'1.0-1.5': {'20.0-50.0': 10, '0.0-10.0': 33, '10.0-15.0': 22, '50.0-1000.0': 24, '15.0-20.0': 5}}
"""
"""
вьюха возвращяет вот так
{'1.0-1.1': {'50.0-1000.0': 24, '20.0-50.0': 10, '0.0-10.0': 33, '10.0-15.0': 22, '15.0-20.0': 5},
'1.5-2.0': {'50.0-1000.0': 24, '20.0-50.0': 10, '0.0-10.0': 33, '10.0-15.0': 22, '15.0-20.0': 5},
'0.0-1.0': {'50.0-1000.0': 24, '20.0-50.0': 10, '0.0-10.0': 33, '10.0-15.0': 22, '15.0-20.0': 5},
'1.0-1.5': {'50.0-1000.0': 24, '20.0-50.0': 10, '0.0-10.0': 33, '10.0-15.0': 22, '15.0-20.0': 5}}
"""