I have data in a file in this format:
+1 1:4 2:11 3:3 4:11 5:1 6:13 7:4 8:2 9:2 10:13
-1 1:2 2:7 3:4 4:12 5:3 6:4 7:3 8:12 9:2 10:12
+1 1:4 2:6 3:3 4:2 5:3 6:5 7:4 8:2 9:3 10:6
and so on....
where the numbers on the left of the colon is an 'index' and numbers on the right of the colon are integers that describe a certain attribute. For each line, if the number on the right of the colon is the same for the same index on another line, I want to store the total amount of +1's and -1's in two separate variables. This is my code so far:
for i in lines:
for word in i:
if word.find(':')!=-1:
att = word.split(':', 1)[-1]
idx = word.split(':', 1)[0]
for j in lines:
clas = j.split(' ', 1)[0]
if word.find(':')!=-1:
if idx ==word.split(':', 1)[0]:
if att ==word.split(':', 1)[0]:
if clas>0:
ifattandyes = ifattandyes+1
else:
ifattandno = ifattandno+1
My problem is att and idx do not seem to update as I think word.find(':') just finds the first instance of a colon and runs with it. Can anyone help?
EDIT:
The above explanation has been confusing. I'm a bit stubborn about how the count of 1s and -1s is acquired. As each pair on each line is read, I want to search through the data for the number of +1s and -1s that the pair is involved in and store them into 2 separate variables. The reason for doing so is to calculate probabilities of each pair leading to a +1 or -1.
+1in the begging of the line?