I have a document like this:
>>> k = {'finance_pl':{'S':{'2008':45,'2009':34}}}
Normal way to access is:
>>> k['finance_pl']['S']
{'2008': 45, '2009': 34}
But, in my case the end user will give me input as finance_pl.S
I can split this and access the dictionary like this:
>>> doc_list = doc.split('.')
>>> k[doc_list[0]][doc_list[1]]
{'2008': 45, '2009': 34}
But, I don't want to do this, since the dictionary structure may change the and
user can give something like this finance_pl.new.S
instead of k['finance_pl']['S']
or k[doc_list[0]][doc_list[1]]
.
I need something to apply the users input directly (Ex: if input is finance_pl.new.S
, I should be able to apply this .split('.')
method to the users input and apply directly).
What is the elegant way to do that ?