我試圖創建一個程序來檢查一個列表中的項目是否不在另一個列表中。它不斷返回行說x值不在列表中。有什麼建議麼?對不起我的代碼,這是相當草率。創建一個比較兩個列表的程序
搜索在數組
文件把.TXT成陣列
with open('Barcodes', 'r') as f:
barcodes = [line.strip() for line in f]
with open('EAN Staging', 'r') as f:
EAN_staging = [line.strip() for line in f]
陣列
list1 = barcodes
list2 = EAN_staging
主代碼
fixed = -1
for x in list1:
for variable in list1: # Moves along each variable in the list, in turn
if list1[fixed] in list2: # If the term is in the list, then
fixed = fixed + 1
location = list2.index(list1[fixed]) # Finds the term in the list
print()
print ("Found", variable ,"at location", location) # Prints location of terms
所以你想知道哪些項目只在其中一個列表中? – DeepSpace
什麼是第一個for list1循環中的x?似乎沒有任何意義。 –
@DeepSpace不,我想檢查條形碼列表中的任何數據是否不在EAS登臺列表中。 – minidave2014