Steven Bethard <[EMAIL PROTECTED]> writes:
> Cameron Walsh wrote:
> > Which brings me to the question, would this solution:
> > B = set(B)
> > A = B + list(x for x in A if x not in B)
> > be faster than this solution:
> > B = set(B)
> > A.sort(key=B.__contains__, reverse=True)
> [timings deleted]
> That said, I'd probably still use the first solution -- it's more
> immediately obvious why that one works.

Wait a minute, the first example looks wrong, B has gotten replaced by
a set and then it's added to a list.

Anyway how about timing

   C = set(A) - set(B)
   A = B + filter(C.__contains__, A)

This scans A twice, but it does more of the work in native code,
without sorting.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to