I have this data (taken part of random data coming from some server):
data={2: [9, ['b', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a']], 3: [9,
['c', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a']], 5: [5, ['c', 'b', 'a',
'b', 'b']], 7: [9, ['c', 'c', 'a', 'b', 'a', 'b', 'a', 'b', 'a']]}
In this data, first number is the key, second value is the number of entries in the bracket following it. eg:- For data
2: [9, ['b', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a']]
2 is the key. 9 is the total number of entries in the bracket which follows it.
Also, for keys having second value less than 9 are to be discarded. I got that data.values() can give me the value as
[[9, ['b', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a']], [9, ['c', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a']], [5, ['c', 'b', 'a', 'b', 'b']], [9, ['c', 'c', 'a', 'b', 'a', 'b', 'a', 'b', 'a']]}
But I am not able to find any way to index within the matrix.
I need to make matrix out of this data as follows:
a b c
2 4 5 0
3 4 4 1
7 4 3 2
The matrix value [1][1] is the sum of a's in key value 2, [1][2] is the sum of b's in key value 2 and [1][3] is the sum of c's in key value 2, [2][1] is the sum of a's in key value 3, and so on..