f | class vector: | f | class vector: |
| | | |
n | def __init__(self, iterable): | n | def __init__(self, values): |
| self.data = list(iterable) | | self.values = list(values) |
| | | |
| def __str__(self): | | def __str__(self): |
n | return ':'.join(map(str, self.data)) | n | return ':'.join(map(str, self.values)) |
| | | |
| def __add__(self, other): | | def __add__(self, other): |
n | return vector([x + y for x, y in zip(self.data, other)]) | n | return vector((v1 + v2 for v1, v2 in zip(self.values, other))) |
| | | |
| def __radd__(self, other): | | def __radd__(self, other): |
| return self.__add__(other) | | return self.__add__(other) |
| | | |
| def __matmul__(self, other): | | def __matmul__(self, other): |
n | return sum([x * y for x, y in zip(self.data, other)]) | n | return sum((v1 * v2 for v1, v2 in zip(self.values, other))) |
| | | |
| def __getitem__(self, index): | | def __getitem__(self, index): |
t | return self.data[index] | t | return self.values[index] |