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