Python solution for string reversal