Reverse Pattern In Python Using Global Variables In Functions