exercise: partition a list by equivalence

John Lenton john at grulic.org.ar
Fri Feb 18 22:14:52 EST 2005


On Fri, Feb 18, 2005 at 04:52:46PM -0800, John Machin wrote:
> > > needs "if rev[first] == rev[second]: continue" here
> >
> > an 'is' is enough, and better.
> 
> Good point. You're redeeming yourself :-)

this, together with you saying that it is hard to explain, makes me
think that you aren't comfortable thinking of lists as mutable
objects.


> > what is magic about it? is it really that horrible?
> 
> Try explaining to the newbies over on the tutor list how despite "res"
> only ever *explicitly* having little bits like [3, 4] appended to it,
> it (or more properly the thing to which it refers) is actually
> festering and growing and being mutated under the surface until at the
> finale it bursts out dripping slime just like the creature from the
> black lagoon ...

understanding why that works, and why it is 'is' and not '==', are
both part of the same thing. Lists are mutable, and you can mutate
them, and they mutate. Unless you actually write code that uses the
fact you will forget it, and it will bite you. Of course, don't use it
just for the heck of it, but that creature you dismiss as a
slime-dripping mutation is actually quite useful.

While I'm at being unpolite, do you really think this code was harder
to understand than the code posted by anton, using numarray?

And, of course, if this code were for anything non-throw-awayable,
there would've been quite a bit of explaining going on between those
lines of code.

Ok, now back to being polite :)

-- 
John Lenton (john at grulic.org.ar) -- Random fortune:
Hay más días que longanizas. 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20050219/cd79a0f8/attachment.sig>


More information about the Python-list mailing list