help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hash Function


From: Przemek Klosowski
Subject: Re: Hash Function
Date: Wed, 5 Dec 2012 15:05:02 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1

On 12/05/2012 10:35 AM, Jordi Gutiérrez Hermoso wrote:
On 5 December 2012 10:07, Jonathan Karsch <address@hidden> wrote:
I am trying to figure out how many distinct words are in a text
document, and how many instances there are of each.

Octave does not have hashes nor sufficiently flexible associative
arrays. I recommend using a language other than Octave for this task.
For example, here is how you can do it in Python:
>
... 18 lines of elegant Python

Here is how to do it in Perl:
>
... 14 lines of elegant Perl

or in write-only quick-and-dirty one-line Perl

perl -lane 'foreach $a (@F) { $w{$a}++}; if (eof) {foreach $a (sort keys %w) { print "$a $w{$a}"}}'

Don't laugh---it's pretty efficient to write it this way: readline is the editor, and it's quite fast to iterate towards a nice output from the initial try of

 perl -lane 'foreach $a (@F) { $w{$a}++}; print %w if eof'


reply via email to

[Prev in Thread] Current Thread [Next in Thread]