List of Numbers

Sean 'Shaleh' Perry shalehperry at attbi.com
Sat Apr 5 14:24:14 EST 2003


On Saturday 05 April 2003 11:13, 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?
>
> Simon

the canonical approach is is to place the numbers in a hash (dictionary in 
python) where the value is the key and stored data is the number of 
occurences.

for each number
   see if dict has number as a key
   if it does, increment the count
   else add the number to the dictionary and set the count to 1

then you just look for any dictionary elements with a count greater than 1.
Or if you just want uniques, you just ask the dictionary for its keys() list.





More information about the Python-list mailing list