Skip to content

Instantly share code, notes, and snippets.

@AstraLuma
Created February 18, 2025 02:12
Show Gist options
  • Select an option

  • Save AstraLuma/3299ff28124a2e8ddeea4da69083f4ad to your computer and use it in GitHub Desktop.

Select an option

Save AstraLuma/3299ff28124a2e8ddeea4da69083f4ad to your computer and use it in GitHub Desktop.
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