Python solution for prob26