Python "why" questions

Gregory Ewing greg.ewing at canterbury.ac.nz
Sun Aug 15 20:33:51 EDT 2010


Ian Kelly wrote:
> On Fri, Aug 13, 2010 at 11:53 AM, Martin Gregorie
> <martin at address-in-sig.invalid> wrote:

>>       real sample[-500:750];

> Ugh, no.  The ability to change the minimum index is evil.

Not always; it can have its uses, particularly when you're
using the array as a mapping rather than a collection.

Pascal had a nice feature where you could use any ordinal
type as an array index, and sometimes it was handy to
have things like an array indexed by the characters
'A' to 'Z', or the values (Red, Green, Blue). Typically
you didn't need to do arithmetic on the indices in those
case, though.

Python addresses this by having separate types for
sequences and mappings.

-- 
Greg



More information about the Python-list mailing list