[Python-ideas] Use the plus operator to concatenate iterators

Grayson, Samuel Andrew sag150430 at utdallas.edu
Wed Aug 5 03:31:37 CEST 2015


I propose that if the iterator class overrides the __add__ method, then use that instead of concatenation.

Therefore

    numpy.array([1, 2, 3]) + numpy.array([3, 2, 1])
    # evaluates to numpy.array([4, 4, 4])

It is already done with the __mul__ function

    a = [1, 2, 3] # or a tuple
    a * 2
    # evaluates to [1, 2, 3, 1, 2, 3]

    b = np.array([1, 2, 3])
    b * 2
    # evaluates to np.array([2, 4, 6])

Sincerely,
Sam G


More information about the Python-ideas mailing list