title: Vectorizing LIst of Unique Words into 0 or 1 using Python
body: <p>I am quite new into Python, and recently have to do on some text processing to do a cosine similarity between two text. </p>
  
  <p>I have currently be able to do on the basic pre-processing on the text such as lowercase them, tokenizing the text, removing stopwords, and stemming of those words by using the NLTK library. And now, I have able to create a list of unique words from all the text files that I got.</p>
  
  <p>Then now, in this list of unique words that I have created, there are only certain words that I would like to vectorize it to 1 (and the rest to 0) according to a textfile that I have. </p>
  
  <p>So for example, after vectorized the list of unique words, it should look something like below:</p>
  
  <pre><code>awesome| best | carry | elephant | fly | home | irresponsible | implicit 
  1      | 1    | 0     | 0        | 0   | 1    | 0             | 0
  </code></pre>
  
  <p>I have tried googling and look through stack overflow here, but it seems one of the the common solution is using the scikit learn - features extraction in converting the list. However, I only wants either 0 or 1... and that the 1 should be specified by a textfile.</p>
  
  <p>For example, there is one textfile (after vectorizing it all into 1) that I would like to compute the similarity with this dictionary... So it should look something like this below:</p>
  
  <p>Text_to_Compare.txt</p>
  
  <pre><code>awesome | fly | implicit
  1       | 1   | 1
  </code></pre>
  
  <p>And then, I will compare the "Text_to_Compare.txt" with the list of unique words and compute the similarity result. </p>
  
  <p>Could anyone kindly guide me on how do I go on vectorize the list of unique words to only 0 or 1, and vectorzing the "Text_to_Compare.txt" to all 1? </p>
  
  <p>Thank you!</p>