Another idea would be to do it several times... like, in the first time, you would only treat keys starting with an "A", in the second time, with a "B"...
Readjust to fit your particular keys :-)
Comment on Re: How to remove duplicates from a large set of keys