fast list search?

Peter Otten __peter__ at web.de
Wed Jun 9 13:51:05 CEST 2004


ramon aragues wrote:

> 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?


>>> import sets
>>> int_set = sets.Set()
>>> for i in [1,2,2,3,4,4,4]:
...     int_set.add(i)
...
>>> int_set
Set([1, 2, 3, 4])
>>>

This requires Python 2.3.

Peter




More information about the Python-list mailing list