Anonymous user
Word frequency: Difference between revisions
→{{header|zkl}}: rewrite
m (→version 1: elided a conditional test from a DO loop (by incorporating it into an UNTIL clause).) |
(→{{header|zkl}}: rewrite) |
||
Line 714:
=={{header|zkl}}==
<lang zkl>fname,count := vm.arglist; // grab cammand line args
File(fname).pump(Void, // read the file line by line and hash words▼
.toList().copy().sort(fcn(a,b){ b[1]<a[1] })[0,count.toInt()]▼
// words may have leading or trailing "_", ie "the" and "_the"▼
RegExp("[a-z]+").pump.fp1(Dictionary().incV)) // line-->(word:count,..)
▲ // have leading or trailing "_", ie "the" and "_the"
▲.toList().copy().sort(fcn(a,b){ b[1]<a[1] })[0,count.toInt()] // hash-->list
.pump(String,Void.Xplode,"%s,%s\n".fmt).println();</lang>
{{out}}
<pre>
$ zkl bbb ~/Documents/Les\ Miserables.txt 10
the,
of,
and,
a,
to,
in,
he,
was,
that,
it,
</pre>
|