f | import string | f | import string |
| | | |
| class Pairs: | | class Pairs: |
n | _a = list(string.ascii_lowercase) + list(string.ascii_uppercase) | n | _alphabet = list(string.ascii_lowercase) + list(string.ascii_upperca |
| | | se) |
| _m = {} | | _mapping_static = {} |
| | | |
n | def __init__(self, s): | n | def __init__(self, size): |
| if s not in Pairs._m: | | if size not in Pairs._mapping_static: |
| Pairs._m[s] = {c: (s + i - 1) % 52 + 1 for i, c in enumerate | | Pairs._mapping_static[size] = {char: (size + idx - 1) % 52 + |
| (self._a)} | | 1 for idx, char in enumerate(self._alphabet)} |
| self._d = Pairs._m[s] | | self._mapping = Pairs._mapping_static[size] |
| | | |
n | def __setattr__(self, k, v): | n | def __setattr__(self, attr, val): |
| if k in self._a: | | if attr in self._alphabet: |
| self._d[k] = v | | self._mapping[attr] = val |
| else: | | else: |
n | super().__setattr__(k, v) | n | super().__setattr__(attr, val) |
| | | |
n | def __getattr__(self, k): | n | def __getattr__(self, attr): |
| if k in self._d: | | if attr in self._mapping: |
| return self._d[k] | | return self._mapping[attr] |
| raise AttributeError() | | raise AttributeError() |
| | | |
| def __repr__(self): | | def __repr__(self): |
t | return ' '.join(sorted(self._a, key=lambda x: self._d[x])) | t | return ' '.join(sorted(self._alphabet, key=lambda x: self._mappi |
| | | ng[x])) |