and the solution written out in words below, also in python (I like this one better)
http://pastebin.com/PapfMhfU