[Tutor] Strange modulus problem

Chris Keelan rufmetal@home.com
Sat, 13 Oct 2001 11:24:27 -0500


On Thu, 11 Oct 2001, Kirby Urner wrote:

> This has to do with iterating over the object you're
> also modifying.

When you explain it that way, it makes perfect sense! For some reason I 
didn't think that the 'for' iteration worked by index. Perhaps there was a 
little gnome who took all of the objects out of a list, laid them out on a 
table and picked them up, one-by-one saying "If I divide six by this, will my 
remainder be zero? Nope? Well throw it out then."

;o)

>
> The code below works because it iterates over a copy

Which is how I'm gonna do this from now on.

[snip]

> This is a common programming error in Python and you're
> lucky to stumble across it in such an illuminating
> manner.  It's very good to make mistakes of this kind
> -- very text book.  You have a promising career as a
> Pythoneer ahead of you (pardon the fortune cookie).

You sound like my singing teacher. He told me that sometimes it was better to 
be loudly wrong than to be quietly right.

Thanks for the help, Kirby.

- Chris