How do they do this? Can python?

Jarno J Virtanen jajvirta at cc.helsinki.fi
Thu Aug 8 03:04:28 EDT 2002


Wed, 7 Aug 2002 09:11:32 GMT Michael Hudson wrote:

> This is the same Rob Pike who wrote "The Practice Of Programming" with
> Kernigan?
> 
> I'm pretty sure there's a text dissociator as an example in that
> book...

Indeed there was. See http://cm.bell-labs.com/cm/cs/tpop/code.html
for more information. Here is my rough translation of the algorithm
in Python http://www.cs.helsinki.fi/u/jajvirta/markov.py based on
the Perl version. 

The main difference in my Python implementation and their Perl
implementation being that I couldn't (and perhaps shouldn't) translate
the extremely non-verbose statement in Perl, namely

    push(@{$statetab{$w1}{$w2}}, $_);

as verbatim to Python. Scripting language versions differ
substantially of those in C, C++ and Java, because of the use of lists
and dictionaries. C++ with use of the standard template library comes
quite close, though. Quite interesting case study comparing handful
of languages, though one shouldn't make too broad conclusions just
from one example. ;-)

(Btw -- it was perhaps only a typo -- but it is spelled "Kernighan" ;-)



More information about the Python-list mailing list