MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / merge

Function merge

sorts/merge_sort.py:32–45  ·  view source on GitHub ↗

Merge two sorted lists into a single sorted list. :param left: Left collection :param right: Right collection :return: Merged result

(left: list, right: list)

Source from the content-addressed store, hash-verified

30 """
31
32 def merge(left: list, right: list) -> list:
33 """
34 Merge two sorted lists into a single sorted list.
35
36 :param left: Left collection
37 :param right: Right collection
38 :return: Merged result
39 """
40 result = []
41 while left and right:
42 result.append(left.pop(0) if left[0] <= right[0] else right.pop(0))
43 result.extend(left)
44 result.extend(right)
45 return result
46
47 if len(collection) <= 1:
48 return collection

Callers 1

merge_sortFunction · 0.70

Calls 3

appendMethod · 0.45
popMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected