Solution in py2.7