[EMAIL PROTECTED] wrote: > Hi, > Frequently I get to do like this: > a = (1, 2, 3, 4) # some dummy values > b = (4, 3, 2, 1) > import operator > c = map(operator.add, a, b) > > I am finding the last line not very readable especially when I combine > couple of such operations into one line. Is it possible to overload > operators, so that, I can use .+ for element wise addition, as, > c = a .+ b > which is much more readable. > > Similarly, I want to use .- , .*, ./ . Is it possible to do? > > thanks. > > - > Suresh
List comprehensions? >>> a = (1, 2, 3, 4) >>> b = (4, 3, 2, 1) >>> import operator >>> c = map(operator.add, a, b) >>> c [5, 5, 5, 5] >>> c1 = [a1+b1 for a1,b1 in zip(a,b)] >>> c1 [5, 5, 5, 5] >>> - Paddy. -- http://mail.python.org/mailman/listinfo/python-list