restructure python code; implement python reverse string;