Steven Bethard wrote:

Yeah, almost certainly since he's looking at lists 3K long. If they were small, you never know since the list comprehension gets the C-code speedup, while sets.Set is Python code:

> [list comprehension]
10000 loops, best of 3: 27.5 usec per loop

> [Python 2.3 Set]
10000 loops, best of 3: 47.7 usec per loop

In the case given, the O(n**2) list comprehension is faster than the O(n) set intersection. Of course, this is not likely to be true with any reasonable sized data. But it's something worth keeping in mind.

Of course if you're working with a dataset that small, it probably doesn't really matter which of these implementations you use.


The exception would be if this were in an inner loop in the actual program and *were* being run 10000 times or more.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to