fast list search?

Thomas Guettler guettli at thomas-guettler.de
Wed Jun 9 12:22:54 CEST 2004


Am Wed, 09 Jun 2004 11:49:19 +0200 schrieb ramon aragues:

> Hi,
> 
> I´ve got a list with more than 500,000 ints. Before inserting new ints, 
> I have to check that it doesn´t exist already in the list.
> 
> Currently, I am doing the standard:
> 
> if new_int not in long_list:
> 	 long_list.append(new_int)
> 
> 
> but it is extremely slow... is there a faster way of doing this in python?

Hi,

Use a dictionary instead of the list:

if not long_dict.has_key(new_int):
    long_dict[new_int]=1

 Thomas




More information about the Python-list mailing list