Created
February 18, 2025 02:12
-
-
Save AstraLuma/3299ff28124a2e8ddeea4da69083f4ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import collections.abc | |
| import sys | |
| class FooneList(collections.abc.MutableSequence): | |
| def __init__(self, *keys: str): | |
| self._store = sys._getframe(1).f_locals | |
| self._keys = keys | |
| def __getitem__(self, index): | |
| return self._store[self._keys[index]] | |
| def __setitem__(self, index, value): | |
| self._store[self._keys[index]] = value | |
| def __delitem__(self, index): | |
| key = self._keys[index] | |
| del self._keys[index] | |
| del self._store[key] | |
| def __len__(self): | |
| return len(self._store) | |
| def insert(self): | |
| raise TypeError("Cannot insert into a FooneList") | |
| fl = FooneList('a', 'b', 'c') | |
| fl[1] = 42 | |
| fl[2] = 69 | |
| fl[3] = "spam" | |
| print(a, b, c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment