Parsing string array for differences

Josiah Carlson jcarlson at uci.edu
Mon Apr 12 15:12:33 EDT 2004


> My below code doesn't do what I need it to do.  What I want is to
> capture the differences between two arrays of data into a new list. 
> So if list A has {Fred, Bob, Jim} and List B has {Jim, George, Fred} I
> want to capture in list C just {Fred, Jim}

According to your example just given, you don't want the difference, you 
want the similarity.

a = {}
a.fromkeys(listA)
listC_similarity = [i for i in listB if i in a]

Using a dictionary for the lookup makes it faster than searching another 
list.

  - Josiah



More information about the Python-list mailing list