Python.

Merge Sort

Python insertion sort - Stack Overflow. 2016. Python insertion sort - Stack Overflow. [ONLINE] Available at: http://stackoverflow.com/questions/12755568/python-insertion-sort. [Accessed 13 August 2016].

def msort(x):
result = []
if len(x) < 2:
return x
mid = int(len(x)/2)
y = msort(x[:mid])
z = msort(x[mid:])
while (len(y) > 0) or (len(z) > 0):
if len(y) > 0 and len(z) > 0:
if y[0] > z[0]:
result.append(z[0])
z.pop(0)
else:
result.append(y[0])
y.pop(0)
elif len(z) > 0:
for i in z:
result.append(i)
z.pop(0)
else:
for i in y:
result.append(i)
y.pop(0)
return result

 

 

 

Teaching Ideas.

Youtube Merge Sort.
Agbonline Teaching Exercises.
Using python.com
20 code Challenges( complete for GCSE 9-1 )
Python Exercises.
Introduction to Python
Python exercises