[Python-ideas] Bring line continuation to multi-level dictionary lookup
Brendan Barnwell
brenbarn at brenbarn.net
Thu Sep 17 06:47:16 CEST 2015
On 2015-09-16 21:07, John Wong wrote:
> Hi everyone.
>
> I work with APIs which have deep nested dictionary structure response.
> Imagine a simplified case:
>
> foo = {1: {2: {3: {4: {5: 6 } } } }
>
> Now imagine I need to get to 6:
>
> foo['1']['2']['3']['4']['5']['6']
You can just use the existing parentheses-based line continuation for this:
(foo[1]
[2]
[3]
[4]
[5]
)
--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no
path, and leave a trail."
--author unknown
More information about the Python-ideas
mailing list