title: Query related to stemming in NLP
body: <p>I am working on hands-on task based on stemming under NLP using python.</p>
  <p>Below is the task which would required to be executed step wise to fetch the result.</p>
  <p>I have completed till step 13 and got stuck at step number 14 and 15 (see below).</p>
  <p>Please help me to know how to perform the step number 14 and 15.</p>
  <h3>TASK</h3>
  <ol>
  <li><p>Import the text corpus <strong>brown</strong>.</p>
  </li>
  <li><p>Extract the list of words associated with text collections belonging to the humor genre. Store the result in the variable <strong>humor_words</strong>.</p>
  </li>
  <li><p>Convert each word of the list humor_words into lower case, and store the result in <strong>lc_humor_words</strong>.</p>
  </li>
  <li><p>Find the list of unique words present in <strong>lc_humor_words</strong>. Store the result in <strong>lc_humor_uniq_words</strong>.</p>
  </li>
  <li><p>Import the corpus <strong>words</strong>.</p>
  </li>
  <li><p>Extract the list of words associated with the corpus words. Store the result in the variable <strong>wordlist_words</strong>.</p>
  </li>
  <li><p>Find the list of unique words present in <strong>wordlist_words</strong>. Store the result in <strong>wordlist_uniq_words</strong>.</p>
  </li>
  <li><p>Create an instance of PorterStemmer named, <strong>porter</strong>.</p>
  </li>
  <li><p>Create an instance of LancasterStemmer named, <strong>lancaster</strong>.</p>
  </li>
  <li><p>Stem each word present in <strong>lc_humor_uniq_words</strong> with porter instance, and store the result in the list <strong>p_stemmed</strong></p>
  </li>
  <li><p>Stem each word present in <strong>lc_humor_uniq_words</strong> with lancaster instance, and store the result in the <strong>listl_stemmed</strong>`</p>
  </li>
  <li><p>Filter the stemmed words from <strong>p_stemmed</strong> which are also present in <strong>wordlist_uniq_words</strong>. Store the result in <strong>p_stemmed_in_wordlist</strong>.</p>
  </li>
  <li><p>Filter the stemmed words from <strong>l_stemmed</strong> which are also present in <strong>wordlist_uniq_words</strong>. Store the result in <strong>l_stemmed_in_wordlist</strong>.</p>
  </li>
  <li><p>Filter the words from <strong>lc_humor_uniq_words</strong> which have the same length as its corresponding stemmed word present in <strong>p_stemmed</strong>, and also contains at least one different character from the corresponding stemmed word. Store the result in the list <strong>p_stemmed_diff</strong>.</p>
  </li>
  <li><p>Filter the words from <strong>lc_humor_uniq_words</strong> which have the same length as its corresponding stemmed word, present in <strong>l_stemmed</strong>, and also contains at least one different character from the corresponding stemmed word. Store the result in list <strong>l_stemmed_diff</strong>.</p>
  </li>
  <li><p>Print the number of words present in <strong>p_stemmed_diff</strong>.</p>
  </li>
  <li><p>Print the number of words present in <strong>l_stemmed_diff</strong>.</p>
  </li>
  </ol>
  <p>-Below is the which I have completed till step 13.</p>
  <pre><code>import nltk
  
  import nltk.corpus
  
  from nltk.corpus import brown
  
  humor_words = brown.words(categories = 'humor')
  
  lc_humor_words = [w.lower() for w in humor_words]
  
  lc_humor_uniq_words = set(lc_humor_words)
  
  from nltk.corpus import words
  
  wordlist_words = words.words()
  
  wordlist_uniq_words = set(wordlist_words)
  
  from nltk.stem import PorterStemmer
  
  porter = PorterStemmer()
  
  from nltk.stem import LancasterStemmer
  
  lancaster = LancasterStemmer()
  
  p_stemmed = []
  
  for word in lc_humor_uniq_words:
  
      p_stemmed.append(porter.stem(word))
  
  l_stemmed = []
  
  for wordd in lc_humor_uniq_words:
  
      l_stemmed.append(lancaster.stem(wordd))
  
  p_stemmed_in_wordlist = [word1 for word1 in p_stemmed if word1 in wordlist_uniq_words]
  
  l_stemmed_in_wordlist = [word2 for word2 in l_stemmed if word2 in wordlist_uniq_words]
  </code></pre>