Why are index() and count() only for mutable sequences?
Tim Peters
tim_one at email.msn.com
Thu Jul 8 23:24:04 EDT 1999
[Bob Alexander]
> There is no modification of the sequence performed by these functions
> -- it seems as though they could be available for all sequences. It
> would certainly be useful for tuples as well as lists (strings, too, for
> that matter, even though we have the more general string.find()).
I don't think there's a deep reason. It was "just true" that immutable
objects (sequences or otherwise) didn't have methods when Python first came
out. But when complex numbers were introduced, they came with a
.conjugate() method, and you can expect strings to grow methods too in 1.6
(Barry Warsaw has checked implementation code for that into the CVS tree,
disabled by default for now -- it's nice!).
As you say, strings have more flexible functions already, and there's reason
to suspect that Guido didn't expect anyone to use tuples of more than a few
elements each.
why-are-tabs-8-spaces<wink>-ly y'rs - tim
More information about the Python-list
mailing list