Following the previous comment I am including only the code necessary to understand the issue. I hope it is understandable. Here is the code:
list_dict = [[] for i in range(10)]
out_dict_2 = {}
out_dict_2.update({'key_a': list_dict, 'key_b': list_dict, 'key_c': list_dict})
for index in range(10):
for line in list_2:
line = line.strip()
line = line.split()
if areallnumbers(line): # check whether all the elements in the list are float
out_dict_2['key_a'][index].append(line[0])
out_dict_2['key_b'][index].append(line[1])
out_dict_2['key_c'][index].append(line[2])
where list_2 looks like EDIT:(I can have also more list of the same type, in my case they are 10--> for index in range(10):
):
['5.00', '-4601.24', '31.73']
['11.04', '-4517.66', '32.51']
['17.08', '-4418.59', '33.24']
['23.12', '-4305.34', '33.93']
['29.17', '-4179.09', '34.59']
......
I am trying to have the first column of each list appended to one dictionary element, i.e. the first column to out_dict_2[key_a][index] and so on, so each value is a list of 10 lists. Something like this (assuming the 10 lists are all equal to the example list I have given:
key_a [['5.00' , '11.04' , '17.08' , '23.12' , ...],...,['5.00' , '11.04' , '17.08' , '23.12' , ...]]
key_b [['-4601.24', '-4517.66', '-4418.59', '-4418.59', ...],...,['5.00' , '11.04' , '17.08' , '23.12' , ...]]
key_c [['31.73' , '32.51' , '33.24' , '33.93' , ...],...,['5.00' , '11.04' , '17.08' , '23.12' , ...]]
What I am actually getting is:
key_a [['5.00', '-4601.24', '31.73'...]['5.00', '-4601.24', '31.73'...]...['5.00', '-4601.24', '31.73'...]
key_b [['5.00', '-4601.24', '31.73'...]['5.00', '-4601.24', '31.73'...]...['5.00', '-4601.24', '31.73'...]
key_c [['5.00', '-4601.24', '31.73'...]['5.00', '-4601.24', '31.73'...]...['5.00', '-4601.24', '31.73'...]
as if each line is appended to each dictionary key, why?