python compare 2 lists for differences code example
Example 1: get list of words that are in two lists using set
list1 = ['little','blue','widget']
list2 = ['there','is','a','little','blue','cup','on','the','table']
list3 = set(list1)&set(list2) # we don't need to list3 to actually be a list
list4 = sorted(list3, key = lambda k : list1.index(k))
Example 2: 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'])**