# Get input from user lst1 = raw_input('Enter a list of values separated by spaces\n? ').split() lst2 = raw_input('Enter a list of values separated by spaces\n? ').split() # find union by adding all elements to a dictionary and take keys tmpDict = {} for item in lst1+lst2: tmpDict[item] = 0 union = tmpDict.keys() # find intersection by going through one list and determing if # the element is also in the other list intersection = [] for item in lst1: if item in lst2: intersection.append(item) print 'Union: ', union print 'Intersection: ', intersection