I have a python dictionary with several keys and I want each key to become a bidimensional array (list of list) like this:
mydict:{'key1':[['l1v1','l1v2'],['l2v1','l2v2']],'key2':[['l1v1','l1v2'],['l2v1','l2v2']]...}
The values I want to assign are chars forming a long string.
myStr = 'a_very_very_very_very_very_very_very_long_string.....'
What I'm doing is something like this:
i = 0
for gr in range(2):
tmp = []
for ch in range(2):
tmp.append(myStr[i])
i += 1
mydict['key1'].append(tmp)
But I'm quite sure this isn't the most efficient/elegant/pythonic way of doing it and I'll have to use a temporal list for every key in my dictionary.
Do you have a suggestion for this? Thanks!
UPDATE
It seems like I made myself misunderstood so I'll give a more detailed explanation of what I'm trying to achieve.
First of all the string is a binary string like this:
binStr = '1001011001110110011011001101001011001....'
So in the first iteration, the first key of my dictionary will be set with the first two characters of the string in a shape of list
'key1':[['1','0']]
Then the second key of my dictionary is set with the next two chars.
'key2':[['0','1']]
And so on until I have no more keys, then in the second iteration my keys will have the whatever next two values in the string and set the second list so I'll have something like this:
'key1':[['1','0'],['0','1']]
'key2':[['0','1'],['0','0']
I tried to do something like the following in the beginning but python can't use list index assigment on the fly.
i = 0
for gr in range(2):
for ch in range(2):
mydict['key1'][gr][ch] = binStr[i]
i += 1