Cumulative Function In Python