title: How to convert List to Json in python3
body: <p>I am a beginner and just started learning python and data structures.
  I have a problem with data type conversion, I need your help, I hope you can give a new idea.</p>
  
  <p>The question is to convert the string to json.</p>
  
  <p>This is row data:</p>
  
  <pre><code>machine learning,inear model,linear regression,least squares
  ,neural network,neuron model,activation function
  ,multi-layer network,perceptron
  ,,,connection right
  ,reinforcement learning,model learning,strategy evaluation
  ,,,strategy improvement
  ,,model-free learning,monte carlo method
  ,,,time series learning
  ,imitate learning,directly imitate learning
  ,,,inverse reinforcement learning
  </code></pre>
  
  <p>Target style:</p>
  
  <pre><code>{'machine learning':
      [{'inear model':
          [{'linear regression':
              [{'least squares': []}]
            }]},
      {'neural network':
          [{'neuron model':
                [{'activation function': []}]
            }]},
      {'multi-layer network':
           [{'perceptron':
                 [{'connection right': []}]
             }]},
      {'reinforcement learning':
           [{'model learning':
                 [{'strategy evaluation': []}]
             }]}
      # ··············
       ]
            }
  </code></pre>
  
  <p>I have successfully completed the field represented by the comma and got a complete list below.    </p>
  
  <pre><code>with open('concept.txt', 'r') as f:
      contents = f.readlines()
  concepts = []
  
  for concept in contents:
      concept = concept.replace('\n', '')
      array = concept.split(',')
      concepts.append(array)
  
  for i in range(len(concepts)):
      for j in range(len(concepts[i])):
          if concepts[i][j] == '':
              concepts[i][j] = concepts[i-1][j]
  print(concepts)
  
  
  &gt;&gt;&gt; [['machine learning', ' linear model', ' linear regression', ' least squares'], 
      ['machine learning', ' neural network', ' neuron model', ' activation function'],
      ['machine learning', ' multi-layer network', ' perceptron'], 
      ['machine learning', ' multi-layer network', ' perceptron', ' connection right'], 
      ['machine learning', ' reinforcement learning', ' model learning', ' strategy evaluation'], 
      ['machine learning', ' reinforcement learning', ' model learning', ' strategy improvement'], 
      ['machine learning', ' reinforcement learning', ' model-free learning', ' Monte Carlo method'], 
      ['machine learning', ' reinforcement learning', ' model-free learning', 'time series learning'], 
      ['machine learning', ' imitate learning', ' directly imitate learning'], 
      ['machine learning', ' imitate learning', ' directly imitate learning', ' inverse reinforcement learning']] 
  </code></pre>
  
  <p>I try to convert two-dimensional list to the corresponding multidimensional dictionary</p>
  
  <pre><code>def dic(list):
      key = list[0]
      list.pop(0)
      if len(list) == 0:
          return {key: []}
      return {key: [dic(list)]}
  
  def muilti_dic(mlist):
      muilti_list = []
      for i in range(len(mlist)):
          dic = dic(mlist[i])
          muilti_list.append(dic)
      return muilti_list
  
  &gt;&gt;&gt; [
       {'machine learning': 
           [{'inear model': 
            [{'linear regression': [{'least squares': []}]}]}]}, 
       {'machine learning': 
          [{'neural network': 
            [{'neuron model': [{'activation function': []}]}]}]}, 
       {'machine learning': 
          [{'multi-layer network': [{'perceptron': []}]}]}, 
       {'machine learning': 
          [{'multi-layer network': 
            [{'perceptron': [{'connection right': []}]}]}]}, 
       {'machine learning': 
          [{'reinforcement learning': 
            [{'model learning': [{'strategy evaluation': []}]}]}]}, 
       {'machine learning': 
          [{'reinforcement learning': 
            [{'model learning': [{'strategy improvement': []}]}]}]}, 
       {'machine learning': 
          [{'reinforcement learning': 
            [{'model-free learning': [{'Monte Carlo method': []}]}]}]}, 
       {'machine learning': 
          [{'reinforcement learning': 
            [{'model-free learning': [{'time series learning': []}]}]}]}, 
       {'machine learning': 
          [{'imitate learning': [{'directly imitate learning': []}]}]}, 
       {'machine learning': [{'imitate learning': [{'directly imitate learning': [{'inverse reinforcement learning': []}]}]}]}
      ]
  </code></pre>
  
  <p>At present, I am stuck in how to merge this multiple multidimensional dictionary into a multidimensional dictionary. </p>
  
  <p>How do I convert the current list into the style required by the question? </p>