Created
October 12, 2024 23:34
-
-
Save omamkaz/dc8c61aee26a0543c9484684f2b92d6d to your computer and use it in GitHub Desktop.
simple built-in list instance, that can work with a dimensions array.
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
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