应用场景:业务给了一份包裹数据,让开发帮忙查询下里面哪些包裹数据还没有从上游回传:
开发根据全量数据,通过sql查到已经收到的数据(只列出查到的数据,省略步骤):
利用python找未收到的数据(此处将excel表中的数据直接拿出来了,因为上个步骤sql里有用到,通过数据做了些删减):
#全量数据
totalData=['BTL_001-40195902','BTL_001-40195905','BTL_001-40195909','BTL_001-40195910','BTL_001-40195933','BTL_001-40195935','BTL_001-40195941',
'BTL_001-40195947','BTL_001-40195947','BTL_001-40195948','BTL_001-40195915','BTL_001-40195779','BTL_001-40195854','BTL_001-40195779',
'BTL_001-40195990','BTL_001-40195829','BTL_001-40195895','BTL_001-40195829','BTL_001-40195895','BTL_001-40196009','BTL_001-40195826',
'BTL_001-40195834','BTL_001-40195826','BTL_001-40195834','BTL_001-40196030','BTL_001-40196031','BTL_001-40196030','BTL_001-40196031',
'BTL_001-40196037','BTL_001-40196052','BTL_001-40196062','BTL_001-40195791','BTL_001-40195786','BTL_001-40195791','BTL_001-40195813',
'BTL_001-40196552','BTL_001-40196553']
#对totalData进行去重
print("全量数据有:")
print(len(totalData))
totalData = list(set(totalData))
print("全量数据做下去重有:")
print(len(totalData))
#收到的数据
receivedData=['BTL_001-40195779','BTL_001-40195786','BTL_001-40195788','BTL_001-40195791','BTL_001-40195806','BTL_001-40195813',
'BTL_001-40195826','BTL_001-40195829','BTL_001-40195834','BTL_001-40195838','BTL_001-40195839','BTL_001-40195850']
#未收到的数据
notReturnedData=[]
for i in totalData:
flag=False
for j in receivedData:
if j==i:
#数据已经收到,跳出循环并将flag的标志改为true
flag=True
break
if(flag==False):
notReturnedData.append(i)
print("未收到的数据量有:")
print(len(notReturnedData))
print("未收到的数据有:")
print(notReturnedData)
结果:
全量数据有:
37
全量数据做下去重有:
28
未收到的数据量有:
21
未收到的数据有:
['BTL_001-40195941', 'BTL_001-40195990', 'BTL_001-40195947', 'BTL_001-40196052', 'BTL_001-40196037', 'BTL_001-40196031', 'BTL_001-40195902', 'BTL_001-40196552'