MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / merge

Function merge

sorts/merge_insertion_sort.py:38–49  ·  view source on GitHub ↗

>>> merge([[1, 6], [9, 10]], [[2, 3], [4, 5], [7, 8]]) [[1, 6], [2, 3], [4, 5], [7, 8], [9, 10]]

(left, right)

Source from the content-addressed store, hash-verified

36
37
38def merge(left, right):
39 """
40 >>> merge([[1, 6], [9, 10]], [[2, 3], [4, 5], [7, 8]])
41 [[1, 6], [2, 3], [4, 5], [7, 8], [9, 10]]
42 """
43 result = []
44 while left and right:
45 if left[0][0] < right[0][0]:
46 result.append(left.pop(0))
47 else:
48 result.append(right.pop(0))
49 return result + left + right
50
51
52def sortlist_2d(list_2d):

Callers 1

sortlist_2dFunction · 0.70

Calls 2

appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected