所以,我有一个巨大的输入文件,看起来像这样:(你可以在这里下载)
1. FLO8;PRI2
2. FLO8;EHD3
3. GRI2;BET2
4. HAL4;AAD3
5. PRI2;EHD3
6. QLN3;FZF1
7. QLN3;ABR5
8. FZF1;ABR5
...
看它就像一个两列的表格,即“;”之前的元素 显示到“;”之后的元素
我想迭代地打印简单的字符串,以显示构成前馈循环的三个元素。上面的示例编号列表将输出:
"FLO8 PRI2 EHD3"
"QLN3 FZF1 ABR5"
...
将第一条输出线解释为前馈循环:
A -> B (FLO8;PRI2)
B -> C (PRI2;EHD3)
A -> C (FLO8;EHD3)
只有这个链接中圈出的那个
所以,我有这个,但它非常慢......有什么建议可以更快地实现吗?
import csv
TF = []
TAR = []
# READING THE FILE
with open("MYFILE.tsv") as tsv:
for line in csv.reader(tsv, delimiter=";"):
TF.append(line[0])
TAR.append(line[1])
# I WANT A BETTER WAY TO RUN THIS.. All these for loops are killing me
for i in range(len(TAR)):
for j in range(len(TAR)):
if ( TAR[j] != TF[j] and TAR[i] != TF[i] and TAR[i] != TAR[j] and TF[j] == TF[i] ):
for k in range(len(TAR )):
if ( not(k == i or k == j) and TF[k] == TAR[j] and TAR[k] == TAR[i]):
print "FFL: "+TF[i]+ " "+TAR[j]+" "+TAR[i]
注意:我不想要自循环...从 A -> A、B -> B 或 C -> C