词表 - 答:书耶稣基督的儿子大卫儿子亚伯拉罕雅各布犹大他的兄弟佩雷斯amminadabwordlist B:akwụkwọjizọskraịstnwadevid nwaebrehamjekọbjudayaụmụnnepirezaminadab
file.txt A:
- 耶稣基督历史的书,大卫的儿子,亚伯拉罕的儿子:
- 亚伯拉罕成为艾萨克的父亲;艾萨克成为雅各布的父亲;雅各成为犹大和他兄弟的父亲;
醇>file.txt B:
- akwụkwọnkekọrọakụkọbanyerejizọskraịst,nwa devid,nwa ebreham:
- ebrehammụrụaịzik; aịzikamụọjekọb; jekọbamụọjudanaụmụnneyandnikom;
醇>
我有2个以上的单词列表(比如A& B)。语言。两者都按顺序包含彼此的单词翻译。我的任务是通过2个单独的files.txt运行这些单词列表,如word-list A到file.txt A,反之亦然,然后为两个txt文件返回一行,每行包含两个单词的索引号-list在txt的每一行上找到它们,如:
- 2:1 7:6 8:7 10:9 12:10 14:12 16:13 [2:1 = txt.file A中的书索引2和txt.file B中的1-akwụkwọ等等]
- 1:1 11:6 13:8 17:10 19:12 20:13 [1:1 = txt.file A中的1个亚伯拉罕索引和txt.file B中的1- ebreham等等]。 见下面的代码:
醇>
import sys
def wordlist(filename):
wordlist = []
with open(filename, 'rb') as f:
for line in f:
wordlist.append(line)
return wordlist
eng = []
for lines in open('eng_try.txt', 'rb'):
line = lines.strip()
eng.append(line)
igb = []
for lines in open('igb_try.txt', 'rb'):
line = lines.strip()
igb.append(line)
i = 0
while i < len(eng):
eng_igb_verse_pair = eng[i] + " " + igb[i]
line = eng_igb_verse_pair.strip().split()
for n in range(0, len(wordlist('eng_wordlist.txt'))):
eng_word = wordlist('eng_wordlist.txt').pop(n)
igb_word = wordlist('igb_wordlist.txt').pop(n)
if eng_word in line and igb_word in line:
print '{0} {1}:{2}'.format(i, line.index[eng_word], line.index[igb_word])
i += 1
这实际上打印为空。我知道我的问题出在该计划的最后一部分。有人可以帮忙吗我不是那个经验丰富的python程序员。如果我没有很好地构建我的解释,请道歉。
答案 0 :(得分:0)
你的意思是这样的:
import sys
def checkLine(line_eng, line_igb):
eng_words = line_eng.split()
igb_words = line_igb.split()
for word in eng_words:
if word in eng:
igb_word = igb[eng.index(word)]
print "%d:%d" % ( eng_words.index(word)+1, igb_words.index(igb_word)+1),
def linelist(filename):
lineslist = []
for line in open(filename, 'rb'):
lineslist.append(line)
return lineslist
eng = []
for lines in open('eng_try.txt', 'rb'):
line = lines.strip()
for w in line.split():
eng.append(w)
igb = []
for lines in open('igb_try.txt', 'rb'):
line = lines.strip()
for w in line.split():
igb.append(w)
eng_lines = linelist("eng_wordlist.txt")
igb_lines = linelist("igb_wordlist.txt")
for n in range(0, len(eng_lines)):
print "%d. " % (n+1),
checkLine(eng_lines[n],igb_lines[n])
print
对于你的文件,我得到了结果:
1. 2:1 7:6 8:7 10:9 12:10 10:9 16:13
2. 1:1 11:7 11:7 17:11 19:14 20:13
BR Parasit Hendersson