Skip to content

Instantly share code, notes, and snippets.

@omamkaz
Created October 12, 2024 23:34
Show Gist options
  • Save omamkaz/dc8c61aee26a0543c9484684f2b92d6d to your computer and use it in GitHub Desktop.
Save omamkaz/dc8c61aee26a0543c9484684f2b92d6d to your computer and use it in GitHub Desktop.
simple built-in list instance, that can work with a dimensions array.
from typing import overload, Any
class List(list):
@overload
def __getitem__(self, t: tuple, /) -> list[Any]: ...
def __getitem__(self, v, /):
if isinstance(v, tuple):
_v = None
for i in v:
if _v is not None:
if not isinstance(_v, (list, tuple, list, set)):
raise IndexError("list index out of range")
_v = _v[i]
else:
_v = self[i]
return _v
return super().__getitem__(v)
data = List([
[0, 1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[2, 3, 4, 5],
])
data[0:2,0,0:3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment