【发布时间】:2017-08-24 13:16:29
【问题描述】:
我需要比较两个数组,其中一个数组的值存在于另一个数组中,我需要在另一个数组中匹配后插入下一个位置。但在我的代码中它什么也没做。
这是我的代码:
arr=[]
result=['Alphabets','reveals','help','opinions','Allah']
words=['Alif-Laam-Meem','NNP','Alphabets','NNPS','of','IN','the','DT',' Arabic','NNP','language','NN','Allah','NNP','and','CC','to','TO', 'whomever','VB','He','PRP','reveals','VBZ','know','VBP','their','PRP','precise','JJ','meanings','NNS']
j=4
k=0
while j<len(words): #words contain text file contents that is split into words
while k<len(result): #result is another array containing subsets of words of file.
if result==words[j]: # if values of results match with values of words
arr.append(words[j+1]) #add next index of words in arr.
j+=1
print(arr)
else:
continue
【问题讨论】:
-
results 是一个空列表,它不包含任何内容
-
数据示例非常有用。将整个数组
result与数组words的元素进行比较,但如果没有您正在使用的数据示例,则无法知道。 -
@N.Ivanov 结果不为空..我需要结果中存在的匹配值的下一个索引值
-
我发表评论的时候,好像你已经更新了答案
-
@N.Ivanov 你能帮我解决这个问题吗?