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?


closed as off-topic by m_goldberg, RunnyKine, ilian, MarcoB, user9660 Apr 3 '16 at 5:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, RunnyKine, ilian, MarcoB, Community
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ Look up Drop[]. $\endgroup$ – J. M. is away 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. is away 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
text = Drop[Import["http://www.gutenberg.org/cache/epub/36/pg36.txt", "Words"], -20000];

42 996


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