I have a list:
list = [ '1', '1,'1', '-1','1','-1' ]
and need to convert it to a dictionary of dictionaries. The first three values in are x y z and the second set three values are x y z. The result should be:
d = { 0:{x:1,y:1,z:1}, 1:{x:-1,y:1,z:-1}}
My attempt:
mylist=[1,1,1,-1,1,-1]
count = 1
keycount = 0
l = {'x':' ','y':' ', 'z':' '}
t = {}
for one in mylist:
if count == 1:
l['x'] = one
print l
if count == 2:
l['y'] = one
print l
if count == 3:
l['z'] = one
print l
count = 0
t[keycount] = l
l = {}
keycount += 1
count = count + 1
print t
But in the result it switches some of the keys of the dictionary? Does anyone have a better solution?
A bit complicated one: