When I need to traverse nested dicts, is a common pattern to do

somedict.get('foo', {}).get('bar', {})

But there is no such equivalent for arrays, wouldn't be nice if we can
follow

somedict.get('foo', {}).get('bar', []).get(10) ... ?

What I do in this case is surround with try/except IndexError and set some
variable to None, or wrap the try/except block in a function. But this is
noise in my opinion, I just want to follow the same reasoning that I have
with dicts:  I'm searching for some path deep nested, and want a default if
not found.

What do you think?

Regards
-- 
“If you're going to try, go all the way. Otherwise, don't even start. ..."
  Charles Bukowski
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/LLK3EQ3QWNDB54SEBKJ4XEV4LXP5HVJS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to