因此,對于家庭作業,我必須找到出現在單詞上的行號(由列表給出)。到目前為止,我有這個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])) 所以我到達這里,因為它超出了范圍,所以我得到了錯誤。我一直在努力,因為這一切現在看起來像胡言亂語。
使用字典找到文件中出現單詞的行號
慕田峪7331174
2021-03-11 10:10:30