On Thu, 2006-12-14 at 15:57 +0000, Nick Maclaren wrote: > In article <[EMAIL PROTECTED]>, > "Fredrik Lundh" <[EMAIL PROTECTED]> writes: > |> > |> > The point is that an index method makes sense on ANY data structure that > |> > can be subscripted by an integer value but, for reasons that aren't at > |> > all clear, is not defined for Python tuples. There is no technical or > |> > mathematical reason why it shouldn't be. > |> > |> so where would you put such an "index" implementation so it would work on > |> ANY data structure that can be subscripted by an integer value ? > > In the same place you put the subscription method, clearly.
Clearly not, because that would force *every* object that implements __getitem__ to also implement index. And to verify the truth of your assertion that index makes sense for "ANY data structure that can be subscripted by an integer value", consider the following theoretical but conceivable examples: 1) A mailbox object that returns the i-th message on subscripting. 2) A scroll cursor in a database that returns the i-th row of the result set. 3) A prime number generator that calculates the i-th prime number. Does .index() make sense for them? How would it be implemented? -Carsten -- http://mail.python.org/mailman/listinfo/python-list