Q:

Compare unequal lists

I want to compare two unequal lists:
a = [6]
b = [6,7,8]

I want following:
if list a == list b:
   #do something for matching elements from both lists
else:
     #do something for non-matching elements

Any suggestions are appreciative. 

A:

If you are looking for the elements which exist in both lists, the following list comprehension should work:
c = [item for item in b if item in a]

Like so:
>>> a = [6]
>>> b = [6,7,8]
>>> c = [item for item in b if item in a]
>>> c
[6]
>>> 

If you want to, say print something every time the values match, use the following for loop:
for i in b:
    if i in a:
        print '%d in both sets!' %(i)
    else:
        print '%d does not match!' %(i)

This runs as:
>>> a = [6, 7]
>>> b = [6, 7, 8]
>>> for i in b:
...     if i in a:
...             print '%d in both sets!' %(i)
...     else:
...             print '%d does not match!' %(i)
... 
6 in both sets!
7 in both sets!
8 does not match!
>>> 

