From 03f994077557e67493f41ba4c3f7aca08da000d4 Mon Sep 17 00:00:00 2001 From: Ashok Bakthavathsalam Date: Wed, 3 Jul 2019 21:01:10 +0530 Subject: [PATCH] Refactored to one pop() (#917) --- sorts/merge_sort.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sorts/merge_sort.py b/sorts/merge_sort.py index ecbad7075..714861e72 100644 --- a/sorts/merge_sort.py +++ b/sorts/merge_sort.py @@ -37,7 +37,7 @@ def merge_sort(collection): ''' result = [] while left and right: - result.append(left.pop(0) if left[0] <= right[0] else right.pop(0)) + result.append((left if left[0] <= right[0] else right).pop(0)) return result + left + right if len(collection) <= 1: return collection @@ -53,4 +53,4 @@ if __name__ == '__main__': user_input = raw_input('Enter numbers separated by a comma:\n').strip() unsorted = [int(item) for item in user_input.split(',')] - print(*merge_sort(unsorted), sep=',') \ No newline at end of file + print(*merge_sort(unsorted), sep=',')