【发布时间】:2017-10-23 03:58:10
【问题描述】:
我想为每次迭代创建一个新数组(或列表)。这是我的代码:
import numpy as np
data2 = open('pathways.dat', 'r', errors = 'ignore')
pathways = data2.readlines()
special_line_indexes = []
PWY_ID = []
line_cont = []
L_PRMR = [] #Left primary
#i is the line number (first element of enumerate), while line is the line content (2nd elem of enumerate)
for CUI in just_compound_id:
for i,line in enumerate(pathways):
if '//' in line:
#fint the indexes of the lines containing //
special_line_indexes = i+1
elif 'REACTION-LAYOUT -' in line:
if CUI in line:
PWY_ID.append(special_line_indexes)
具体来说,我想为 CUI 的不同迭代(第一个 foor 循环)创建一个不同的数组 PWY_ID。我最终得到的是一个包含所有输出的长数组。也许使用字典会更有效,但我不确定如何在 for 循环中实现它......
【问题讨论】: