title: Split string list into dictionary keys in python
body: <p>I have a string 'request.context.user_id' and I want to split the string by '.' and use each element in the list as a dictionary key.  Is there a way to do this for lists of varying lengths without trying to hard code all the different possible list lengths after the split?</p>
  
  <pre><code>parts = string.split('.')
  if len(parts)==1:
      data = [x for x in logData if x[parts[0]] in listX]
  elif len(parts)==2:
      data = [x for x in logData if x[parts[0]][parts[1]] in listX]
  else:
      print("Add more hard code")
  </code></pre>
  
  <p>listX is a list of string values that should be retrieved by x[parts[0]][parts[1]
  logData is a list obtained from reading a json file and then the list can be read into a dataframe using json_normalize... the df portion is provided to give some context about its structure.. a list of dicts:</p>
  
  <pre><code>import json
  from pandas.io.json import json_normalize
  
  with open(project_root+"filename") as f:
      logData = json.load(f)
  
  df = json_normalize(logData)
  </code></pre>