Posting code might help us to find the problem, BUT, why are you using lists? If you are checking to see if names from a are in b and if they are not identically ordered, wouldn't hashes be a better data structure? It sounds as though if you used hashes you could iterate over one, say, a's keys and see if they are in b.