Py学习  »  Python

Append函数在python中没有给出所需的结果

Frustrated • 5 年前 • 1396 次点击  

下面给出的代码没有给出下面指定的所需结果。我试了很多次排列都没有成功。

posLabels = ['abc', 'def', 'ab3','ab4', 'ab5']
senPosList = [('abc','def','ghi'),('jkl','mno','pqr','123'), 
('stu','vwx')]
senVecList= []
senVec = []
posLabels[0] in senPosList[0]

for x in range(3):
    for i in range(5):
        if posLabels[i] in senPosList[x]:
            senVec.append(1)
        else: 
            senVec.append(0)
    senVecList.append(senVec)
print(senVecList)

[[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] 

我想要 senVecList = [[1, 1, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]]

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53469
 
1396 次点击  
文章 [ 3 ]  |  最新文章 5 年前