Nested loops is strangely slow, totally at a loss.

Ian Kelly ian.g.kelly at gmail.com
Wed Dec 10 02:13:58 EST 2014


On Tue, Dec 9, 2014 at 11:30 PM, Chris Angelico <rosuav at gmail.com> wrote:
> Are you sure it isn't? Your 'space' is an iterable cubic
> cross-product. Your first loop checks (0,0,0) which is the first
> element returned, and is thus fast... but it also *consumes* that
> first element. The next time you test it, the entire space gets
> consumed, looking for another (0,0,0), which won't exist. That means
> iterating over 580**3 == 195112000 (two hundred million) tuples, and
> that *is* going to be slow.

Huh, I wasn't even aware that membership tests worked on iterables with no
__contains__ method. Seems odd to me that 'x in y' should be supported but
not 'len(y)'.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141210/4cf9551b/attachment.html>


More information about the Python-list mailing list