From 25c0bd3fbb866312fc6727a58494f3168cabbf7d Mon Sep 17 00:00:00 2001 From: Coregame Date: Thu, 4 Oct 2018 13:36:16 +0700 Subject: [PATCH] minor improvement (readability) in Insertion Sort --- sorts/insertion_sort.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sorts/insertion_sort.py b/sorts/insertion_sort.py index b7a4aa7a3..59917ac05 100644 --- a/sorts/insertion_sort.py +++ b/sorts/insertion_sort.py @@ -30,9 +30,8 @@ def insertion_sort(collection): [-45, -5, -2] """ for index in range(1, len(collection)): - while 0 < index and collection[index] < collection[index - 1]: - collection[index], collection[ - index - 1] = collection[index - 1], collection[index] + while index > 0 and collection[index - 1] > collection[index]: + collection[index], collection[index - 1] = collection[index - 1], collection[index] index -= 1 return collection