Implement Insertion sort in Python
As this looks like a school assignment, I'm answering with a bunch of questions for the student of algorithms to ponder:


Why do you think an empty list should be invalid input?
Could you think of a more descriptive name for the parameter than a?
You have a loop from 1 to length of array. This looks like an off by one error. Normally one would loop over indexes of 0..length-1. Could this loop be improved so it doesn't look suspicious?
Why are you using an outer for-loop and an inner while loop? Why not not in reverse? Why not use the same looping construct for both?
As this is an insertions sort, how do you perform an insertion to Python list, and where in this code is that insertion used?
How can you make sure that this solution really works? Could you write an automated test to check that it's correctly sorting various inputs?