Slow comparison between two lists
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Thu Oct 23 17:49:37 EDT 2008
On Thu, 23 Oct 2008 05:03:26 -0700, Jani Tiainen wrote:
> But in my case running that loop takes about 10 minutes. What I am doing
> wrong?
Others have already suggested you have a O(N**2) algorithm. Here's an
excellent article that explains more about them:
http://www.joelonsoftware.com/articles/fog0000000319.html
The article is biased towards low-level languages like C. In Python the
way to avoid them is to use sets or dicts, or to keep the list sorted and
use the bisect module.
--
Steven
More information about the Python-list
mailing list