Python:我需要一些关于以下程序的建议

时间:2017-04-05 15:09:33

标签: python

list1 = ["experience","as","a","java","developer"] 
list2 = ["B","O","O","B","I"] 
list3 = ["java","developer"]
number = 0
print(list2)
for i in list1:
    for j in list3:
        if(i!=j):
            for l in range(number,len(list2)):
                list2[number] = "O"
                number += 1       
print(list2)

此处"B"表示"经验","O"代表" as"等等。

预期产出:

["O","O","O","B","I"]

我的输出:

["O","O","O","O","O"]

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题是正确的,你需要这样做:

for i in range(len(list1)):
    if list1[i] not in list3:
        list2[i] = "O"

print(list2)

输出[' 0',' 0',' 0',' B','我']