James has suggested that Python be enhanced so that >>> a, b += c, d is a short-hand for >>> a += c >>> b += d
Myself, James and Matthew wrote >> > Does it IN PRACTICE bring sufficient benefits to users? >> I found myself needing this when I was writing a monte-carlo >> simulation in python that required incrementing a tallying counter >> from a subroutine. > Wouldn't a numpy array be very suited for this kind of task? Perhaps, James, you might like to refactor your code so that >>> tally += simulation(args) does what you want. As Matthew points out, you could use numpy.array. Or code your own class, by providing __add__ and __iadd__ methods. >>> import numpy >>> a = numpy.array([1, 2]) >>> b = numpy.array([3, 4]) >>> a + b array([4, 6]) >>> a += b >>> a array([4, 6]) -- Jonathan _______________________________________________ Python-ideas mailing list [email protected] https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
