因此,对于家庭作业,我必须找到出现在单词上的行号(由列表给出)。到目前为止,我有这个def index(f,l): 'str,list(str)==nonetype' infile=open(f) file=infile.read() b=file.split('\n') G=file.splitlines() infile.close count=1 res=0 c={} a=[] for i in b: a+=[i] for n in l: while res <len(G): small={G[res]:count} c.update(small) count+=1 res+=1 if (a[res] in c) and (n in a[res]): print (n+'{}'.format(c[count])) 所以我到达这里,因为它超出了范围,所以我得到了错误。我一直在努力,因为这一切现在看起来像胡言乱语。
2 回答

小唯快跑啊
TA贡献1863条经验 获得超2个赞
def index(filename, wordlist):
# Initialize some variable with meaningful names
with open(filename) as infile:
for line in infile:
# Do something with the line
return # something
这里有一些更多的提示,可以让你的代码更简洁,但可能过于超前现在:enumerate,defaultdict(list)
添加回答
举报
0/150
提交
取消