How come tuples don't have an index method?
Terry Reedy
tjreedy at home.com
Fri Sep 7 12:05:43 EDT 2001
"Michael Abbott" <michael at rcp.co.uk> wrote in message
news:Xns91157F87ABEE6michaelrcpcouk at 194.238.50.13...
> Some code:
>
> months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
> 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
>
> ...
>
> # Raises an exception iff the value doesn't start with a
month
> monthIn = months.index(value[:3]) + 1
>
> I thought, just for tidiness, and to ensure that the months array
doesn't
> accidentially get modified in place, that I'd change it into a
tuple.
>
> Unfortunately, I can't call months.index anymore!
>
> Is there a good reason for not supporting index on tuples? And for
that
> matter, why not also support count?
Historically, immutable types did not have attributes. But then
complex numbers with z.real, z.imag came along, then strings got
methods, so I see no good reason not to give tuples methods also.
Seems like a PEP project.
Terry J. Reedy
More information about the Python-list
mailing list