fast list search?

From: ramon aragues (ramon.aragues_at_gmx.net)
Date: 06/09/04


Date: Wed, 09 Jun 2004 11:49:19 +0200
To: python-list@python.org

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?

Thanks a lot,

Ramon Aragues



Relevant Pages

  • Re: fast list search?
    ... > I´ve got a list with more than 500,000 ints. ... Before inserting new ints, ... is there a faster way of doing this in python? ... Thomas ...
    (comp.lang.python)
  • integer type conversion problem/question
    ... I have a integer in Python (Python integers are implemented as C long ... an unsigned int, modifies it and then passes it back to Python. ... is done since the random number generator uses unsigned ints. ... but excessive detail may be confusing. ...
    (comp.lang.python)
  • integer type conversion problem/question
    ... I have a integer in Python (Python integers are implemented as C long ... an unsigned int, modifies it and then passes it back to Python. ... is done since the random number generator uses unsigned ints. ... but excessive detail may be confusing. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: bool behavior in Python 3000?
    ... and False as if they were 1 and 0 than it is to introduce them to a two element boolean algebra. ... Python has lists and dicts and sets ... despite them not being ints, ... bools being ints is more surprising than the opposite would be. ...
    (comp.lang.python)
  • Re: bool behavior in Python 3000?
    ... But I guess that you are probably trying to make the point that True and False are instances of a _subtype_ of int rather than ints, under the mistaken idea that this pedantry would matter. ... However, you may notice that I said _integers_, which is not the same thing as ints: the Python types int and bool are both implementations of the mathematical "integer" or "whole number". ... You can only cast aspersions in C, ...
    (comp.lang.python)