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