title: Python - text mining - TypeError: __hash__ method should return an integer
body: <p>I am working on a classification problem in python. Fact is, I'm not good yet in python. So I have the same problem since a long time now and I don't know how to fix it. I hope you could help me :)</p>
  
  <p>This is my code :</p>
  
  <pre><code>tableau = pandas.DataFrame({'Exigence':exigence,'Résumé':resume})    
  
  df2, targets = encode_target(tableau,"Exigence")
  features = list(df2.columns[:4])
  
  for line in resume:
     terms = prep.ngram_tokenizer(text=line)
     mx.add_doc(doc_id='some-unique-identifier',
                doc_class=df2["Target"],
                doc_terms=terms,
                frequency=True,
                do_padding=True)
  </code></pre>
  
  <p>And I have this error :</p>
  
  <pre><code>objects are mutable, thus they cannot be hashed
  Traceback (most recent call last):
  
    File "&lt;ipython-input-9-072e9c71917a&gt;", line 7, in &lt;module&gt;
      do_padding=True)
  
    File "C:\Users\nouguierc\AppData\Local\Continuum\Anaconda3\lib\site-  packages\irlib\matrix.py", line 222, in add_doc
      if doc_class in self.classes:
  
  TypeError: __hash__ method should return an integer
  </code></pre>
  
  <p>When I go the the line 222 of matrix.py I see this :</p>
  
  <pre><code>    if doc_class in self.classes:
          self.classes[doc_class].add(my_doc_terms)
  </code></pre>
  
  <p>The function containing those lines is :</p>
  
  <pre><code>def add_doc(self, doc_id = '', doc_class='', doc_terms=[], 
              frequency=False, do_padding=False):
      ''' Add new document to our matrix:
          doc_id: Identifier for the document, eg. file name, url, etc. 
          doc_class: You might need this in classification.
          doc_terms: List of terms you got after tokenizing the document.
          frequency: If true, term occurences is incremented by one.
                      Else, occurences is only 0 or 1 (a la Bernoulli)
          do_padding: Boolean. Check do_padding() for more info.
      ''' 
      # Update list of terms if new term seen.
      # And document (row) with its associated data.
      my_doc_terms = SuperList()
      for term in doc_terms:
          term_idx = self.terms.unique_append(term)
          #my_doc_terms.insert_after_padding(self.terms.index(term))
          if frequency:
              my_doc_terms.increment_after_padding(term_idx,1)
          else:
              my_doc_terms.insert_after_padding(term_idx,1)
      self.docs.append({  'id': doc_id, 
                          'class': doc_class, 
                          'terms': my_doc_terms})
      # Update list of document classes if new class seen.
      # self.classes.unique_append(doc_class)
      if doc_class in self.classes:
          self.classes[doc_class].add(my_doc_terms)
      else:
          self.classes[doc_class] = my_doc_terms
      if do_padding: 
          self.do_padding()
  </code></pre>
  
  <p>What do you think about my problem? </p>