Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
class Nested:
def __init__(self, data): = data
def __getitem__(self, item):
if is None:
return Nested(None)
if isinstance(item, int) and isinstance(, list):
if len( >= item:
return Nested([item])
return Nested(None)
if isinstance(item, str) and isinstance(, dict):
if item in
return Nested([item])
return Nested(None)
return Nested(None)
def __nonzero__(self):
return bool(
def __str__(self):
return str(
a = {'b': {'c': [123]}}
a = Nested(a)
c = a['b']['c'][0]['123']['5']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.