1
我有兩個列表,我喜歡瀏覽它們以獲得匹配和差異 但我不明白爲什麼我的索引沒有達到列表的末尾 有我的代碼:獲取兩個列表的匹配
recordedEvents=[u'/app//wakeup', u'/app/hdmi/state', u'/homepage/ws/view', u'/homepage//activate', u'/live//activate', u'/live//zap', u'/live/ctazap/view', u'/live/ppluspminus/zap', u'/app//keypress', u'/app//keypress', u'/app//keypress', u'/app//keypress', u'/app//keypress', u'/app//keypress', u'/live/virtualzappinglistbanner/zap', u'/live/virtualzappinglistbanner/view', u'/live/digit/zap', u'/live/noright/view', u'/live/digit/zap', u'/live/ctazap/view', u'/live/ctazap/click', u'/live/toolbox/view', u'/app//keypress', u'/live/toolbox/click', u'/isf//activate', u'/app//keypress', u'/live//activate', u'/live//zap', u'/live/ctazap/view', u'/live/ctazap/click', u'/live/toolbox/view', u'/app//keypress', u'/app//keypress', u'/app//keypress', u'/app//standby', u'/app/favorites/state', u'/app/optin/state', u'/app/perso/state', u'/app/tnt/state', u'/app/hdd/state', u'/app/switches/state', u'/qos/live/', u'/trap//temperature']
expectedEvents=[u'/app//wakeup', u'/app/hdmi/state', u'/homepag/ws/view', u'/homepage//activate', u'/live//activate', u'/live//zap', u'/live/ppluspminus/zap', u'/app//keypress', u'/live/virtualzappinglistbanner/zap', u'/live/virtualzappinglistbanner/view', u'/live/digit/zap', u'/live/noright/view', u'/live/digit/zap', u'/live/toolbox/view', u'/live/toolbox/click', u'/isf//activate', u'/app//keypress', u'/live//activate', u'/live//zap', u'/live/toolbox/view', u'/live/toolbox/click', u'/app//standby', u'/app/favorites/state', u'/app/optin/state', u'/app/perso/state', u'/app/tnt/state', u'/app/hdd/state', u'/app/switches/state', u'/qos/live/', u'/trap//temperature']
indexR = 0
indexE = 0
n_expected_event=['ctazap']
while indexR!=len(recordedEvents)-1:
if recordedEvents[indexR]==expectedEvents[indexE]:
print "[event]"+str(expectedEvents[indexE])+" Matching OK"
indexE+=1
indexR+=1
else:
for diff in n_expected_event:
if str(diff) in str(recordedEvents[indexR]):
print"[missing] "+str(recordedEvents[indexR])
indexR+=1
有結果:
[event]/app//wakeup Matching OK
[event]/app/hdmi/state Matching OK
[event]/homepage/ws/view Matching OK
[event]/homepage//activate Matching OK
[event]/live//activate Matching OK
[event]/live//zap Matching OK
[missing] /live/ctazap/view
[event]/live/ppluspminus/zap Matching OK
[event]/app//keypress Matching OK
[event]/live/virtualzappinglistbanner/zap Matching OK
[event]/live/virtualzappinglistbanner/view Matching OK
[event]/live/digit/zap Matching OK
[event]/live/noright/view Matching OK
[event]/live/digit/zap Matching OK
[missing] /live/ctazap/view
[missing] /live/ctazap/click
[event]/live/toolbox/view Matching OK
[event]/live/toolbox/click Matching OK
[event]/isf//activate Matching OK
[event]/app//keypress Matching OK
[event]/live//activate Matching OK
[event]/live//zap Matching OK
[missing] /live/ctazap/view
[missing] /live/ctazap/click
[event]/live/toolbox/view Matching OK
預先感謝您
謝謝你的回答我已經使用了列表集結束函數交集,但是這給了我結果沒有排序例如[event]/app // wakeup匹配OK應該是匹配數字1 –