improving a huge double-for cycle

skip at skip at
Thu Sep 18 14:44:29 CEST 2008

    Alex> Unfortunately my len(IN) is about 100.000 and the running time
    Alex> about 15h !!!! :(

    Alex> Any idea to improve it?


More immediately, note that you are building a list of len(IN) ints every
time through the inner loop.  A quick hit might be this simple change:

    indexes = range(len(IN))
    for i in indexes: #scan all elements of the list IN
      for j in indexes:
        if i != j:
         if (IN[i].coordinates[0] == IN[j].coordinates[0] and
             IN[i].coordinates[1] == IN[j].coordinates[1]):


More information about the Python-list mailing list