Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to merge Two Sorted Arrays in Python

def merge(num1, num2):
    arr3 = num1+num2
    arr3.sort()
    return arr3
    
arr1 = [3, 5, 6, 10]
arr2 = [1, 2, 7, 8, 11, 12]
assert merge(arr1, arr2) == [1, 2, 3, 5, 6, 7, 8, 10, 11, 12]
arr1 = [1, 3, 4, 5]
arr2 = [2, 4, 6, 8]
assert merge(arr1, arr2) == [1, 2, 3, 4, 4, 5, 6, 8]
arr1 = [5, 8, 9]
arr2 = [4, 7, 8]
assert merge(arr1, arr2) == [4, 5, 7, 8, 8, 9]
Source by levelup.gitconnected.com #
 
PREVIOUS NEXT
Tagged: #How #merge #Two #Sorted #Arrays #Python
ADD COMMENT
Topic
Name
2+1 =