Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>FIRST APPROACH -</strong></p> <p>Well, using regular expression(s) you could do like so - </p> <pre><code>import re re.sub('g+', 'g', 'omgggg') re.sub('l+', 'l', 'lollll') </code></pre> <p>etc.</p> <p>Let me point out that using regular expressions is a very fragile &amp; basic approach to dealing with this problem. You could so easily get strings from users which will break the above regular expressions. What I am trying to say is that this approach requires lot of maintenance in terms of observing the patterns of mistakes the users make &amp; then creating case specific regular expressions for them.</p> <p><strong>SECOND APPROACH -</strong></p> <p>Instead have you considered using <code>difflib</code> module? It's a module with helpers for computing deltas between objects. Of particular importance here for you is <code>SequenceMatcher</code>. To paraphrase from <a href="http://docs.python.org/library/difflib.html" rel="nofollow">official documentation</a>- </p> <blockquote> <p>SequenceMatcher is a flexible class for comparing pairs of sequences of any type, so long as the sequence elements are hashable. SequenceMatcher tries to compute a "human-friendly diff" between two sequences. The fundamental notion is the longest <em>contiguous</em> &amp; junk-free matching subsequence.</p> </blockquote> <pre><code>import difflib as dl x = dl.SequenceMatcher(lambda x : x == ' ', "omg", "omgggg") y = dl.SequenceMatcher(lambda x : x == ' ', "omgggg","omg") avg = (x.ratio()+y.ratio())/2.0 if avg&gt;= 0.6: print 'Match!' else: print 'Sorry!' </code></pre> <p>According to documentation, any ratio() over 0.6 is a close match. You might need to explore tweak the ratio for your data needs. If you need more stricter matching I found any value over 0.8 serves well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload