1st non-trivial program - gentle criticism requested

Emile van Sebille emile at fenx.com
Thu Apr 13 14:53:56 CEST 2000


Just a few observations I have along the lines of
'oh!, you mean this' as I read your code.

>>> a = [0,0,0,0,0,0]
>>> for i in xrange(10000):
 j = int(whrandom.choice('012345'))

>>> print max(a)
>>> a.index(max(a))


Emile van Sebille
emile at fenx.com

----- Original Message -----
From: Paul-Michael Agapow <p.agapow at ic.ac.uk>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Thursday, April 13, 2000 1:10 AM
Subject: 1st non-trivial program - gentle criticism requested

> Hi y'all,
> I'm experimenting with Python for a number of purposes (an embedded
> language for simulations, a tool for exploring experimental data, a
> first programming language) and so I've cobbled together my first
> non-trivial program. With some trepidation, I post it here in the
> that experts will be able to coach me in "The Python Way". I realise
> looks like C++ (my usual langauge), but criticisms of style would be
> useful too.
> Basically, it's a recreation of the "Methinks it is a weasel"
> detailed by Richard Dawkins in "The Blind Watchmaker". A population of
> strings is compared vs. a target string and the "fittest" (the one
> most resembles the target) is used to form the next generation, with a
> small chance. So it's a simple genetic algorithm.
> thanks
> p-m
> --- program follows

More information about the Python-list mailing list