我试图创建一个程序来检查一个列表中的项目是否不在另一个列表中。它不断返回行说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