Pep8 Compliant Deep Dictionary Access
What is the pep8 compliant way to do deep dictionary access? dct = { 'long_key_name_one': { 'long_key_name_two': { 'long_key_name_three': {
Solution 1:
Perhaps not the best way, but it works:
a = dct['long_key_name_one']['long_key_name_two']
b = a['long_key_name_three']['long_key_name_four']['long_key_name_five']
But this also works, which is the suggested method:
print (dct['long_key_name_one']['long_key_name_two']
['long_key_name_three']['long_key_name_four']
['long_key_name_five'])
Solution 2:
If you use it inside a function (and you could use print() as a function since 2.7 afaik)
You could just use implicit concatenation within a parentheses
print(dct['long_key_name_one']
['long_key_name_two']
['long_key_name_three']
['long_key_name_four']
['long_key_name_five'])
Post a Comment for "Pep8 Compliant Deep Dictionary Access"