I have some data looks like in this format
2,3,4
3,4,5
5,6,7
I pack the array as:
with open('house_price_data.txt') as data:
substrings = data.read().split()
array = [map(int, substring.split(',')) for substring in substrings]
My task is to do some calculation like this for each data in the set:
(2-3)**2 + (3-3)**2 + (5-3)**2
(3-4)**2 + (4-4)**2 + (5-4)**2
My expected answer is C1 = 5 and C2 = 2
I wrote a code like this
for [a for a, b, c in array] in range (0,2):
C1 = (([a for a, b, c in array]) - 3)**2
C2 = (([b for a, b, c in array]) - 4)**2
But it is not working. For the purpose of for loop, I think it will read the data 2,3,5 one by one minus 3 and square the result one by one and sum the total results. So how can I improve it?
A part from that, I also have problems with this code
[a for a, b, c in array]
[b for a, b, c in array]
[c for a, b, c in array]
I need to call array many times with this code with item a, b and c of the array in the program, when I have such codes in the program error massage come
not enough values to unpack (expected 3, got 0)
How can I do to make changes?