[Tutor] Iterating through a list of replacement regex patterns

Steven D'Aprano steve at pearwood.info
Sat Sep 4 12:16:12 CEST 2010

On Sat, 4 Sep 2010 11:57:00 am David Hutto wrote:
> First of all, I'll respond more thoroughly tomorrow, when I can
> review what you said more clearly, but for now I'll clarify.
> Here is the whole code that I'm using:
> http://pastebin.com/Ak8DFjrb

David, in genrandfiles() you say this:

    mkd = 0
    # This makes the range dir for range of the files for later matched
    # len of dictionary regex word matches
    if mkd == 0:

Firstly, I don't understand the comment. All the words individually make 
sense, but altogether, they look like something generated by one of 
those monkeys with a typewriter... *wink*

Secondly, given that in the previous line you just set mkd = 0, is there 
any possible circumstance where the test "if mkd == 0" would *not* 
succeed? Why don't you just unconditionally call makerangedirs()?

    mkd = 0

> This is supposed to recreate a thought experiment I've heard about,
> in which, if you have an infinite amount of monkeys, with an infinite
> amount of typewriters, they'll eventually spit out Shakespeare.

Ha ha, well, I don't want to discourage you, but the sun will burn out 
and die long before you get more than a couple of words of Shakespeare 
from this technique.

On the other hand, there are ways to randomly generate non-random text 
*incredibly quickly*. See http://en.wikipedia.org/wiki/Weasel_program 
for more detail.

Steven D'Aprano

More information about the Tutor mailing list