python compare lists code example

Example 1: compare lists element wise python

[ x&y for (x,y) in zip(list_a, list_b)]

Example 2: python compare each item of one list

import itertools
for a, b in itertools.combinations(mylist, 2):
    compare(a, b)

Example 3: compare two list in python

>>> s = ['a','b','c']   
>>> f = ['a','b','d','c']  
>>> ss= set(s)  
>>> fs =set(f)  
>>> print ss.intersection(fs)   
   **set(['a', 'c', 'b'])**  
>>> print ss.union(fs)        
   **set(['a', 'c', 'b', 'd'])**  
>>> print ss.union(fs)  - ss.intersection(fs)   
   **set(['d'])**