merge two sorted list of items in python
My question has to do with figuring out different ways to merge 2 sorted items? I try to find an easy way to merge 2 sorted items.
def merge(arr1, arr2):
return sorted(arr1 + arr2)
# Example: merge([1, 4, 7], [2, 3, 6, 9]) => [1, 2, 3, 4, 6, 7, 9]
I'm not sure if I'm complicating it. This uses a built-in function, meaning it's harder to mess up the implementation details.
I also find that I can use the merge() function from cypthon's heapq.
Wondering if there's any thought of using other method likee the following:
Gist for Merge in python
def merge(arr1, arr2):
return sorted(arr1 + arr2)
# Example: merge([1, 4, 7], [2, 3, 6, 9]) => [1, 2, 3, 4, 6, 7, 9]
I'm not sure if I'm complicating it. This uses a built-in function, meaning it's harder to mess up the implementation details.
I also find that I can use the merge() function from cypthon's heapq.
Wondering if there's any thought of using other method likee the following:
Gist for Merge in python
Комментарии
Отправить комментарий