Может сделать что-то вроде (см. Также комментарии):
x = (1,2) # create a `tuple`
b = map(lambda x: x * 5,x) # do a `map` object for multiplying 5 to all of them
print(x) # print the `tuple`
t=iter((1,2)) # do an generator object using `iter`, so able to use `next` to access every next element
print(tuple(map(lambda x: x-next(t),b))) # do the `next` and another `map`, to subtract as you wanted
Лучше всего создать класс:
from __future__ import division
class MyClass:
def __init__(self,t):
self.t=t
def __mul__(self,other):
return MyClass(tuple(map(lambda x: x*other,self.t)))
def __truediv__(self,other):
return MyClass(tuple(map(lambda x: x/other,self.t)))
def __sub__(self,other):
gen=iter(other)
return MyClass(tuple(map(lambda x: x-next(gen),self.t)))
def __add__(self,other):
gen=iter(other)
return MyClass(tuple(map(lambda x: x+next(gen),self.t)))
def __repr__(self):
return str(tuple(self.t))
Тогда теперь можно делать все что угодно:
x = MyClass((1,2))
b = x*5
print(b)
print(b-(1,2))
Выход:
(5, 10)
(4, 8)
Также можно сделать сложение:
x = MyClass((1,2))
b = x*5
print(b)
print(b-(1,2)+(3,4))
Выход:
(5, 10)
(7, 12)
Также деление:
x = MyClass((1,2))
b = x*5
print(b)
print((b-(1,2)+(3,4))/2)
Вывод:
(5, 10)
(3.5, 6.0)