title: How to dynamically move inside a nested dict in Python
body: <p>I have a dict with a dynamical number of nested dicts inside of it, something like:</p>
  
  <pre><code>my_dict = {"a": {"b": {"c: {...}}}}
  </code></pre>
  
  <p>I need to dynamically move inside this dict, for instance I'd like to do the following:</p>
  
  <pre><code>levels = ["a", "b", "c"]
  my_dict[levels[0]][levels[1]][levels[2]] = "something"
  </code></pre>
  
  <p>where the number of items inside "levels" may vary. </p>
  
  <p>I can partially achieve the same result for a limited number of items inside "levels" by writing something like this:</p>
  
  <pre><code>if len(levels) == 1:
      my_dict[levels[0]] = "something"
  elif len(levels) == 2:
      my_dict[levels[0]][levels[1]] = "something"
  elif len(levels) == 3:
      my_dict[levels[0]][levels[1]][levels[2]] = "something"
  (...)
  </code></pre>
  
  <p>but I'm looking for a more general and elegant solution.</p>
  
  <p>Is there a way to do this?</p>