[Tutor] Poor style to use list as "array"?

Angus Rodgers angusr at bigfoot.com
Mon Jul 6 02:14:50 CEST 2009


On Mon, 06 Jul 2009 01:02:10 +0100, I hastily wrote:

>Incidentally, I forgot to quote the next line:
>
>count[-1] = m

That was copied-and-pasted from an older version of the program,
with less descriptive identifiers.  'm' should be 'amnt'.

>Of course, this is much better incorporated into the loop, thus:
>
>for i in range(LEN):
>    (count[i], amnt) = divmod(amnt, value[i])
>
>[...]
>
>So it looks like we should have something like:
>
>plural = {'penny':'pennies'}
>
>counts = {}
>for val in value:
>    (count, amnt) = divmod(amnt, val)
>    counts[val] = count

Better, of course (I still haven't run it, but it should work):

counts = {}
for val in value:
    (counts[val], amnt) = divmod(amnt, val)

>I'm much happier now, thanks!

... but also rather annoyed with myself.
-- 
Angus Rodgers


More information about the Tutor mailing list