3
$\begingroup$

The task I need to do is to import a text book from here http://www.gutenberg.org/cache/epub/36/pg36.txt, then drop the last 20000 words from it and determine how many times the remaining words occur.

text = Drop[Import["http://www.gutenberg.org/cache/epub/36/pg36.txt", "Words"], -20000];

wordcounts = WordCounts[text];

top30 = Take[Transpose[{Keys@wordcounts, Values@wordcounts}], 30];
TableForm[top30, TableHeadings -> {None, {"Words", "Count"}}];

Why doesn't the above code work?

$\endgroup$
  • 3
    $\begingroup$ Look up Drop[]. $\endgroup$ – J. M.'s technical difficulties Apr 2 '16 at 16:32
  • $\begingroup$ Will it work with words? Or is it just going to drop characters instead of words? Sorry I am asking, can't check it up right now. $\endgroup$ – cubus14 Apr 2 '16 at 16:36
  • 4
    $\begingroup$ ...maybe you should show the code you already have, so that we aren't left guessing. $\endgroup$ – J. M.'s technical difficulties Apr 2 '16 at 16:50
  • 3
    $\begingroup$ Drop[Import["http://www.gutenberg.org/cache/epub/36/pg36.txt", "Words"], -20000]? $\endgroup$ – kglr Apr 2 '16 at 17:20
  • $\begingroup$ WordCounts takes a single string as it 1st argument. You have given it a list of words. Since you already have a list, use Counts. $\endgroup$ – m_goldberg Apr 3 '16 at 15:29
7
$\begingroup$
text = Drop[Import["http://www.gutenberg.org/cache/epub/36/pg36.txt", "Words"], -20000];
Length@text

42 996

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.