title: How to return nested dictionary from function
body: <p>Is it possible to make a function that will return a nested dict depending on the arguments?</p>
  
  <pre><code>def foo(key):
      d = {'a': 1, 'b': 2, 'c': {'d': 3, 'e': 4}, }
      return d[key]
  
  foo(['c']['d']) 
  </code></pre>
  
  <p>I waiting for:</p>
  
  <pre><code>3
  </code></pre>
  
  <p>I'm getting:</p>
  
  <pre><code>TypeError: list indices must be integers or slices, not str
  </code></pre>
  
  <p>I understanding that it possible to return a whole dict, or hard code it to return a particular part of dict, like </p>
  
  <pre><code>if 'c' and 'd' in kwargs:
      return d['c']['d']
  elif 'c' and 'e' in kwargs:
          return d['c']['e']
  </code></pre>
  
  <p>but it will be very inflexible</p>