Clustering distance matrix Python

def TMclstr(fp): import scipy.cluster.hierarchy as sch import scipy.spatial.distance as ssd #read represent id list replist=read_clstr_represent(fp) lenlist=len(replist) #read TMscore matrix vec=[] f=file('TM.txt') for i in range(0,lenlist): for j in range(i+1,lenlist): a = f.readline().strip().split() t=1-float(a[2]) vec.append(t) f.close() #Clustering linkage_matrix=sch.linkage(ssd.squareform(vec)) #print linkage_matrix ind=sch.fcluster(linkage_matrix,0.95) inx=range(0,lenlist) data=zip(ind,inx) data.sort() for i,j in data: print replist[j],i