I have a data structure:
my_list = [0] {key1: [1, 2, 3]
key2: [4, 5, 6]
key3: .....
key4: .....}
[1] {key1: [.......]
key2: [... etc.
That is, a list of 4 dictionaries, each dictionary having 4 keys and each key a list of 3 values. Nice and consistent.
I want to loop through each value in each list and update it with an external function. This external function takes 2 arguments (the value I'm updating and the float value contained in its respective key). It's a basic bit of math but the problem is in iterating through the files as it is getting complex and I'm getting lost.
What I have done so far:
def Efunction_conversion(my_list):
converted_dict_list = []
for i in range(0,4):
new_dict = {key:[external_function(float(key), value) for key, value in my_list[i].iteritems()]} ##problems occur here
converted_dict_list.append(new_dict)
return converted_dict_list
The code is not working and it may be obvious to others why.
The external function:
def external~_function(key, value):
E = ((value - key)/key)**2
return E
And the error, TypeError: unsupported operand type(s) for -: 'list' and 'float'
So the line main iteration line is passing a list instead of each element it seems.