In this piece of code, we will be learning to quote our logic to implement the insertion sort using python.

It is less efficient on large lists than advanced algorithms such as quicksort, heapsort, or merge sort.

- Define a function named
**insort(a)**. - Use for loop, with range(1, len(a)).
- Use while loop and check a[j],a[j+1]=a[j+1],a[j] then j is decremented.
- Use the function to sort the array.
- Using for loop, print the array.
- Exit

**Algorithm:**

**Code:**

```
def insort(a):
for i in range(1, len(a)):
b=a[i]
j=i-1
while j>=0 and b<a[j]:
a[j],a[j+1]=a[j+1],a[j]
j -= 1
a = [ 5, 6, 4, 1,3,2]
insort(a)
for i in a:
print (i)
```

**Output:**

```
1
2
3
4
5
6
```

Report Error/ Suggestion