Spaces:
Runtime error
Runtime error
Download bidict.py from PrecisionContent/DU: direct link, hf CLI and curl.
- Browser
- Download file 716 Bytes
-
https://huggingface.co/spaces/PrecisionContent/DU/resolve/main/bidict.py
- Command line
-
hf download hf://spaces/PrecisionContent/DU/bidict.py
-
curl -L -o bidict.py https://huggingface.co/spaces/PrecisionContent/DU/resolve/main/bidict.py
716 Bytes
| class bidict(dict): | |
| def __init__(self, *args, **kwargs): | |
| super(bidict, self).__init__(*args, **kwargs) | |
| self.inverse = {} | |
| for key, value in self.items(): | |
| self.inverse.setdefault(value, []).append(key) | |
| def __setitem__(self, key, value): | |
| if key in self: | |
| self.inverse[self[key]].remove(key) | |
| super(bidict, self).__setitem__(key, value) | |
| self.inverse.setdefault(value, []).append(key) | |
| def __delitem__(self, key): | |
| self.inverse.setdefault(self[key], []).remove(key) | |
| if self[key] in self.inverse and not self.inverse[self[key]]: | |
| del self.inverse[self[key]] | |
| super(bidict, self).__delitem__(key) |