1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| def diff(listA,listB): retA = [i for i in listA if i in listB] retB = list(set(listA).intersection(set(listB)))
print "retA is: ",retA print "retB is: ",retB
retC = list(set(listA).union(set(listB))) print "retC1 is: ",retC
retD = list(set(listB).difference(set(listA))) print "retD is: ",retD
retE = [i for i in listB if i not in listA] print "retE is: ",retE
def main(): listA = [1,2,3,4,5] listB = [3,4,5,6,7] diff(listA,listB)
if __name__ == '__main__': main()
|