defaultdict "", . :
d = defaultdict(lambda: (0, 0.0))
, int float , , , defaultdict.
+= ; - , :
left, right = d["key"]
d["key"] = (left + 2, right + 3)
:, + =, , , . fileoffset numpy, , , , tuple , : :
class vector(tuple):
def __add__(self, other):
return type(self)(l+r for l, r in zip(self, other))
def __sub__(self, other):
return type(self)(l-r for l, r in zip(self, other))
def __radd__(self, other):
return type(self)(l+r for l, r in zip(self, other))
def __lsub__(self, other):
return type(self)(r-l for l, r in zip(self, other))
from collections import defaultdict
d = defaultdict(lambda:vector((0, 0.0)))
for k in range(5):
for j in range(5):
d[k] += (j, j+k)
print d
( ) += ( __iadd__), tuple . Python , .