add functional python solution without global state

No global state
No class