Skip to content

Instantly share code, notes, and snippets.

@christabor
Last active November 24, 2016 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christabor/a08762ac6e9b56215113a27f43827839 to your computer and use it in GitHub Desktop.
Save christabor/a08762ac6e9b56215113a27f43827839 to your computer and use it in GitHub Desktop.
kinda sorta numpy style array and also dict.
class SuperDict():
def __init__(self, **kwargs):
self.items = dict(**kwargs)
def __getitem__(self, key):
if isinstance(key, tuple):
_curr = self.items
for num in key:
_curr = _curr[num]
return _curr
return self.items[key]
class SuperList():
def __init__(self, args):
self.items = list(args)
def __getitem__(self, key):
if isinstance(key, tuple):
_curr = self.items
for num in key:
_curr = _curr[num]
return _curr
return self.items[key]
if __name__ == '__main__':
sup = SuperList([
[[1, 2, 3], [1, 2, 3], [1, 2, 3]], [[1, 2, 3], [1, 2, 3], [1, 2, 3]]])
res = sup[1, 2, 2]
print('res', res)
sup = SuperDict(foo1=dict(bar1=dict(foo2='bar2')))
res = sup['foo1', 'bar1', 'foo2']
print('res', res)
assert res == 'bar2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment