syntax philosophy

Tuang tuanglen at hotmail.com
Tue Nov 18 00:26:34 EST 2003


"Diez B. Roggisch" <deets_noospaam at web.de> wrote in message news:<bpbgoc$oa4$03$1 at news.t-online.com>...
> Hi,
> 
> > But I'm surprised at what you apparently have to go through to do
> > something as common as counting the frequency of elements in a
> > collection. For example, counting word frequency in a file in Perl
> > means looping over all the words with the following line:
> > 
> > $histogram{$word}++;
> 
> Is this all thats needed - or is it actually something like this:
> 
> for $word in $words:
>    $histogram{$word}++
> 
> (I've never used perl, so I blatantly mix python/perl syntax here - but I
> think you'll understand anyway :))

Yes, you guessed correctly. I just left out the loop wrapper, which is
essentially the same as the pseudocode version you wrote above,
because it's about the same as Python's. I was just talking about the
"guts" of the loop. ;-)




More information about the Python-list mailing list