Best way to merge/sort two sorted lists?...

Terry Reedy tjreedy at udel.edu
Thu Dec 6 21:51:53 EST 2007


"Aaron Watters" <aaron.watters at gmail.com> wrote in message 
news:1230064b-603d-4386-b68c-a913c5cf80d3 at s12g2000prg.googlegroups.com...
| While trying to optimize some NUCULAR libraries I discovered
| that the best way to merge 2 sorted lists together
| into a new sorted list is to just append
| them and re-sort.

The current version of list.sort (timsort) was designed to take advantage 
of pre-existing order.  It should discover the 2 sorted sublists and merge 
them together.  It will not really re-sort the way it would with random 
data.

A psyco/Python version can be faster only because it avoids the comparisons 
need to discover the existing sorted sublists.

tjr






More information about the Python-list mailing list