title: Python - Expected list using most_common is different to the one given for less frequent in number
body: <p>This is the question given</p>
  <pre><code>        Define a function called 'stringmethod ; which takes five parameters. 
          • The first parameter is para, which takes a string sentence. 
          • The second parameter is speciall, which takes a string of special characters. 
          • The third parameter is speciall, which takes a single string of special characters. 
          • The fourth parameter is listl, which takes a list of strings. 
          • The fifth parameter is strfind, which takes a string. 
  
  The function definition code stub is given in the editor. Generate print statements based on the following conditions: 
          • Remove all the special characters from para specified in speciall and save them in the variable wordl. 
          • Get the first 70 characters from words, reverse the strings, save it in variable rword2, and print it. 
          • Remove all the wide spaces from rword2, join the characters using the special character specified in speciall, and print the joint string. 
          • If every string from listl is present in para, then format the print statement as follows: 
             o &quot;Every string in {listl } were present&quot; 
          • else 
            o &quot;Every string in {listl } were not present&quot; 
          • Split every word from wordl and print the first 20 strings as a list. 
          • Calculate the less frequently used words whose count &lt; 3. and print the last 20 less frequent words as a list. • Print the last index in wordl, where the substring strfind is found. 
          
         Input Format for Custom Testing 
          • In the first line, the string 'para' is given. 
          • In the second line, the string 'speciall is given. 
          • In the third line, the string 'special2' is given. 
          • The fourth line contains an integer a the size of the listl. 
          • In the next line, strfind is given. 
           
  </code></pre>
  <p>Below is the modified query where i have put the entire program where i have written for the query.</p>
  <pre><code>import math
  import os
  import random
  import re
  import sys
  
  
  
  #
  # Complete the 'strmethod' function below.
  #
  # The function accepts following parameters:
  #  1. STRING para
  #  2. STRING spch1
  #  3. STRING spch2
  #  4. LIST li1
  #  5. STRING strf
  #
  
  from collections import Counter
  def stringmethod(para, special1, special2, list1, strfind):
      word1 = ''.join(i for i in para if not i in special1)
  
      word2 = word1[69::-1] 
      print(word2)
      
      rem=word2.replace(&quot; &quot;,&quot;&quot;)
      sp=special2.join(rem)
      print(sp)
      
      if all(x in para for x in list1): 
          print(&quot;Every string in  {} were present&quot; .format(list1) ) 
      else: 
          print(&quot;Every string in {} were not present &quot; .format(list1)) 
      
      sp2 = word1.split()
      print(sp2[0:20])
  
      l = list(word1.split())
              
      sorted_items = [w for w, _ in Counter(l).most_common()]
      print(sorted_items[-20:])
  
      print(word1.rindex(strfind))
  
  if __name__ == '__main__':
      para = input()
  
      spch1 = input()
  
      spch2 = input()
      
      qw1_count = int(input().strip())
  
      qw1 = []
  
      for _ in range(qw1_count):
          qw1_item = input()
          qw1.append(qw1_item)
  
      strf = input()
  
      stringmethod(para, spch1, spch2, qw1, strf)
  </code></pre>
  <p>Below is the input provided</p>
  <pre><code>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sem odio, varius nec aliquam nec, tempor commodo ante. Pellentesque sit amet augue vel ante dictum placerat ut ut sapien. Proin maximus eu diam in posuere. Suspendisse in lectus in lectus finibus auctor. Nam sed porttitor arcu. Vestibulum augue odio, posuere quis libero sed, pharetra sollicitudin est. Donec sit amet nunc eu nisi malesuada elementum id ut purus.Nunc sit amet % massa rhoncus, venenatis eros sit amet, ornare augue. Nunc a mi sed est tincidunt facilisis at nec diam. Donec nec ex lorem. Morbi vitae diam tincidunt, dignissim arcu ut, facilisis nisi. Maecenas non felis #ullamcorper, viverra augue id, consequat_nunc. Suspendisse potenti. Proin tempor, sapien ut ornare placerat, sapien mauris luctus sapien, eget aliquam turpis urna at quam. Sed a&amp;eros vel@ ante vestibulum vulputate. Suspendisse vitae vulputate velit. Suspendisse! ligula nisl, semper ut sodales et, ultricies porttitor felis. Nunc ac mattis erat, aliquet pretium risus. Nullam quis congue lacus, et mollis nulla. Nunc laoreet in nisi sit amet facili*sis. Cras rutrum justo ut eros mollis volutpat. Sed quis mi nunc. Nunc sed bibendum nibh, quis bibendum tortor.
  ,_!@*%#$.
  ,
  3
  adipiscing
  Aliquam
  Suspendisse
  vulputate
  </code></pre>
  <p>Where i have got the below result , where you can see everything matches, except the 20 less frequently used words part.</p>
  <pre><code>ido mes mauqilA tile gnicsipida rutetcesnoc tema tis rolod muspi meroL
  i,d,o,m,e,s,m,a,u,q,i,l,A,t,i,l,e,g,n,i,c,s,i,p,i,d,a,r,u,t,e,t,c,e,s,n,o,c,t,e,m,a,t,i,s,r,o,l,o,d,m,u,s,p,i,m,e,r,o,L
  Every string in  ['adipiscing', 'Aliquam', 'Suspendisse'] were present
  ['Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'Aliquam', 'sem', 'odio', 'varius', 'nec', 'aliquam', 'nec', 'tempor', 'commodo', 'ante', 'Pellentesque', 'sit']
  ['semper', 'sodales', 'ultricies', 'ac', 'mattis', 'erat', 'aliquet', 'pretium', 'risus', 'Nullam', 'congue', 'lacus', 'nulla', 'laoreet', 'Cras', 'rutrum', 'justo', 'volutpat', 'nibh', 'tortor']
  851
  </code></pre>
  <p>Whereas the output they need is</p>
  <pre><code>['ultricies', 'ac', 'mattis', 'erat', 'aliquet', 'pretium', 'risus', 'Nullam', 'congue', 'lacus', 'mollis', 'nulla', 'laoreet', 'Cras', 'rutrum', 'justo', 'volutpat', 'bibendum', 'nibh', 'tortor']
  </code></pre>
  <p>Whereas i've got as below, which doesn't seem to be incorrect</p>
  <pre><code>['semper', 'sodales', 'ultricies', 'ac', 'mattis', 'erat', 'aliquet', 'pretium', 'risus', 'Nullam', 'congue', 'lacus', 'nulla', 'laoreet', 'Cras', 'rutrum', 'justo', 'volutpat', 'nibh', 'tortor']
  </code></pre>