1
我有兩個列表和b。我想提取相似和不相似的項目。事情是[i]在b [i]之內,例如[0] == b [0:3]。我在這裏嘗試的解決方案獲得類似的(在else語句中),但不是不相似的(如果語句)。 if語句會創建多個輸入,請指出我缺少的內容。提取內容的列表
a = [[1,2,3], [9,8,3], [1,3,5], [2,3,8], [0,3,5], [5,5,7]]
b = [[1,2,3,4,5,6], [4,5,6,8,6,0], [9,8,3,7,8,9], [5,5,7,0,3,9]]
temp, temp1 = [], []
for i in a:
for j in b:
if i != j[0:3]:
temp.append(j)
else:
temp1.append(j)
#print temp should output [[1,3,5], [2,3,8], [0,3,5]] but it gives something different
#print temp1 [[1, 2, 3, 4, 5, 6], [9, 8, 3, 7, 8, 9], [5, 5, 7, 0, 3, 9]] is fine