Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might also consider using <code>collections.counter</code> if you are using Python >=2.7</p> <p><a href="http://docs.python.org/library/collections.html#collections.Counter" rel="nofollow noreferrer">http://docs.python.org/library/collections.html#collections.Counter</a></p> <p>It adds a number of methods like 'most_common', which might be useful in this type of application.</p> <p>From Doug Hellmann's PyMOTW:</p> <pre><code>import collections c = collections.Counter() with open('/usr/share/dict/words', 'rt') as f: for line in f: c.update(line.rstrip().lower()) print 'Most common:' for letter, count in c.most_common(3): print '%s: %7d' % (letter, count) </code></pre> <p><a href="http://www.doughellmann.com/PyMOTW/collections/counter.html" rel="nofollow noreferrer">http://www.doughellmann.com/PyMOTW/collections/counter.html</a> -- although this does letter counts instead of word counts. In the <code>c.update</code> line, you would want to replace <code>line.rstrip().lower</code> with <code>line.split()</code> and perhaps some code to get rid of punctuation.</p> <p><strong>Edit:</strong> To remove punctuation here is probably the fastest solution:</p> <pre><code>import collections import string c = collections.Counter() with open('DataSO.txt', 'rt') as f: for line in f: c.update(line.translate(string.maketrans("",""), string.punctuation).split()) </code></pre> <p>(borrowed from the following question <a href="https://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string-in-python">Best way to strip punctuation from a string in Python</a>)</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.
 

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