Skip to main content
edited tags
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481
title, thanks, and tags
Source Link
rolfl
  • 98.2k
  • 17
  • 220
  • 419

Please suggest improvements on Khan inspired Insertion Sort implementation in Python

I just watched a Khan Academy [video][1]video on Insertion Sort and I've tried to write an implementation in Python. Please suggest corrections or improvements on this program:

unsorted_list=[45,99,1,-22,7,3,294,10,36]

def insertion_sort(unsorted):
    for i in range(1,len(unsorted)):
        for j in range(i):
            if unsorted[i]<unsorted[j]:
                temp = unsorted[j]    
                unsorted[j]=unsorted[i]
                unsorted[i]=temp
                    
    return unsorted 
     
print insertion_sort(unsorted_list)

Thanks!! [1]: http://www.khanacademy.org/video/insertion-sort-algorithm?playlist=Computer%20Science

Please suggest improvements on Insertion Sort implementation in Python

I just watched a Khan Academy [video][1] on Insertion Sort and I've tried to write an implementation in Python. Please suggest corrections or improvements on this program:

unsorted_list=[45,99,1,-22,7,3,294,10,36]

def insertion_sort(unsorted):
    for i in range(1,len(unsorted)):
        for j in range(i):
            if unsorted[i]<unsorted[j]:
                temp = unsorted[j]    
                unsorted[j]=unsorted[i]
                unsorted[i]=temp
                    
    return unsorted 
     
print insertion_sort(unsorted_list)

Thanks!! [1]: http://www.khanacademy.org/video/insertion-sort-algorithm?playlist=Computer%20Science

Khan inspired Insertion Sort

I just watched a Khan Academy video on Insertion Sort and I've tried to write an implementation in Python. Please suggest corrections or improvements on this program:

unsorted_list=[45,99,1,-22,7,3,294,10,36]

def insertion_sort(unsorted):
    for i in range(1,len(unsorted)):
        for j in range(i):
            if unsorted[i]<unsorted[j]:
                temp = unsorted[j]    
                unsorted[j]=unsorted[i]
                unsorted[i]=temp
                    
    return unsorted 
     
print insertion_sort(unsorted_list)
Source Link
infoquad
  • 231
  • 2
  • 2

Please suggest improvements on Insertion Sort implementation in Python

I just watched a Khan Academy [video][1] on Insertion Sort and I've tried to write an implementation in Python. Please suggest corrections or improvements on this program:

unsorted_list=[45,99,1,-22,7,3,294,10,36]

def insertion_sort(unsorted):
    for i in range(1,len(unsorted)):
        for j in range(i):
            if unsorted[i]<unsorted[j]:
                temp = unsorted[j]    
                unsorted[j]=unsorted[i]
                unsorted[i]=temp
                    
    return unsorted 
     
print insertion_sort(unsorted_list)

Thanks!! [1]: http://www.khanacademy.org/video/insertion-sort-algorithm?playlist=Computer%20Science