title: Appending a list to another list in python
body: <p>I have a <code>.txt</code> file that contains data like this :</p>
  <pre><code>math,mathematics
  data,machine-learning-model
  machine-learning,statistics,unsupervised-learning,books
  orange,lda
  machine-learning,deep-learning,keras,tensorflow
  keras,similarity,distance,features
  
  </code></pre>
  <p>Now, I want to store each line as a list in a bigger list .</p>
  <p>The expected output for sentences is something  like this :</p>
  <pre><code>sentences = [['math', 'mathematics'],
  ['data', 'machine-learning-model'],
  ['machine-learning', 'statistics', 'unsupervised-learning', 'books'],
  ['orange', 'lda']]
  
  </code></pre>
  <p>This is what I tried :</p>
  <pre><code>temp_tokens = []
  sentences = []
  
  fp  = open('tags.txt')
  lines = fp.readlines()
  for line in lines:
      temp_tokens.clear()
      for word in line.split(','):
          if word.strip('\n'):
              temp_tokens.append(word)
              temp_tokens = [e.replace('\n','') for e in temp_tokens]
      
      print(temp_tokens)
      sentences.append(temp_tokens)
      
  
  print(sentences)    
  
  </code></pre>
  <p>Now , when I <code>print(temp_tokens)</code> , I get the following output :</p>
  <pre><code>['math', 'mathematics']
  ['data', 'machine-learning-model']
  ['machine-learning', 'statistics', 'unsupervised-learning', 'books']
  ['orange', 'lda']
  ['machine-learning', 'deep-learning', 'keras', 'tensorflow']
  ['keras', 'similarity', 'distance', 'features']
  ['machine-learning']
  </code></pre>
  <p>which is perfectly fine. But, the individual lists are not properly appended to the list <code>sentences</code>. When I do <code>sentences.append(temp_tokens)</code>. The sentences list looks like this :</p>
  <p>It only contains the individual tokens in each line and not the row itself as a list .</p>
  <pre><code>[['data'], ['machine-learning'], ['orange'], ['machine-learning'], ['keras'], ['machine-learning\n'], ['machine-learning'], ['dataset'], ['lstm\n'], ['python'], ['python'], ['reinforcement-learning'], ['machine-learning'], ['machine-learning'], ['machine-learning'], ['machine-learning'], ['overfitting'], ['machine-learning'], ['machine-learning'], ['time-series'], ['machine-learning'], ['linear-regression'], ['python'], ['keras'], ['python'], ['python'], ['pytorch\n'], ['machine-learning'], ['machine-learning'], ['machine-learning'], ['machine-learning'], ['gradient-descent\n'], ['python'], ['image'], ['dataset'], ['python'], ['neural-network'], ['machine-learning'], ['feature-selection'], ['nlp'], ['machine-learning'], ['python'], ['machine-learning'], ['cnn'], ['machine-learning'], ['neural-network'], ['machine-learning'], ['machine-learning'], ['deep-learning'], ['machine-learning'], ['python'], ['tensorflow'], ['machine-learning'], ['machine-learning'], ['machine-learning']
  </code></pre>
  <p>Can someone please tell me what is wrong with my code ? Why is the list '<code>temp_tokens</code>' not appended to '<code>sentences</code>' as a complete list but only as individual tokens ?</p>
  <p>Can someone explain ?</p>