mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27:02 +00:00
Refactored to one pop() (#917)
This commit is contained in:
parent
4fb4cb4fd1
commit
03f9940775
|
@ -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=',')
|
||||
print(*merge_sort(unsorted), sep=',')
|
||||
|
|
Loading…
Reference in New Issue
Block a user