How come tuples don't have an index method?

Michael Abbott michael at rcp.co.uk
Fri Sep 7 07:29:59 EDT 2001


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?



More information about the Python-list mailing list