I have a code where I am trying to compare hydrophilic and hydrophobic interactions. My categories are 'Hydrophilic', 'Hydrophobic' and 'Other'. Every time I try to find out how many of each interaction category there is, I always get always get "Other:0" regardless of how many there should actually be. I know that every file I've tested has plenty of interactions that should be in 'Other'.
I've used an almost identical code successfully for a different project and can't work out what's different now. I have also made sure all the line spacing and indentation is perfect and it still has this problem :(
I tried:
Hydrophilic = 0
Hydrophobic = 0
Other = 0
with open(filename) as f:
lines = f.readlines()
for line in lines:
values = line.split(",")
if values[1] == "HYDROPHOBIC":
Hydrophobic += 1
elif values[1] == "HBOND" or "WEAK_HBOND" or "POLAR" or "WEAK_POLAR":
Hydrophilic += 1
else:
Other += 1
sizes = {'Hydrophilic':Hydrophilic, 'Hydrophobic':Hydrophobic, 'Other':Other}
print(sizes)
and was hoping for it to print something along the lines of (Hydrophilic:7, Hydrophobic:4, Other:13) but always get Other:0.
I tried replacing 'elif' for 'if' and got different numbers for hydrophobic and hydrophilic (still 0 for other). I tried swapping the order so that the hydrophilic values are added first and ended up with 0 hydrophobic and 0 other.