Grid Function In Python