correct the errors in python generator