In a response to this postthis post I wrote a solution in Python. It passed all the test cases given, so I would like help making it more pythonic and reducing the almost repeated lines.
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/