List of Numbers

Peter Hansen peter at engcorp.com
Sat Apr 5 21:08:16 EST 2003


Simon Faulkner wrote:
> 
> I have a list of about 5000 numbers in a text file - up to 14 digits
> each.
> 
> I need to check for duplicates.
> 
> What would people suggest as a good method?

And after all those other replies, I still have to wonder *what*
you plan to do once you've found duplicates?  Remove them, 
quiet-like, so your list has just non-duplicated entries?
Report on all the duplicates?  Something else?

The solution can be different depending on what you plan to do...

(E.g. the dictionary approach is excellent for ending up with
a list with no duplicates, provided you don't care about
the ordering of the resulting list.  It's also the simplest
by far in Python, if you don't even care to know whether there
*were* duplicates, nor which they were.)

-Peter




More information about the Python-list mailing list