Sorting by item_in_another_list

Paul Rubin http
Wed Oct 25 09:11:19 CEST 2006


Fredrik Lundh <fredrik at pythonware.com> writes:
> >   desired_result = B + sorted(x for x in A if x not in B)
> assuming that "keep the existing order" means what it says, you might
> as well replace "sorted" with a list comprehension.

Hmm.  I didn't read it that way, but yeah, if that's what the OP meant
then the sort could be skipped.  I thought he just wanted a stable
sort, which the sorting primitives now promise.



More information about the Python-list mailing list