merge

corsort.merge(xs, i, j, k, lt=None)[source]

Merge two consecutive sorted portions of a list.

Assume that xs[i:j] and xs[j:k] are already sorted, and merge-sort them.

Parameters:
  • xs (list) – Values to sort.

  • i (int) – Beginning of the left portion.

  • j (int) – Beginning of the right portion.

  • k (int) – End (excluded) of the right portion.

  • lt (callable) – lt(x, y) is the test used to determine whether element x is lower than y. Default: operator “<”.

Examples

>>> my_xs = [0, 1, 4, 6, 7, 2, 3, 5, 8]
>>> merge(my_xs, i=0, j=5, k=9)
>>> my_xs
[0, 1, 2, 3, 4, 5, 6, 7, 8]