Op 2005-11-28, Aahz schreef <[EMAIL PROTECTED]>: > In article <[EMAIL PROTECTED]>, > Christoph Zwerschke <[EMAIL PROTECTED]> wrote: >> >>For instance, I just wanted to use the index() method on a tuple which >>does not work. It only works on lists and strings, for no obvious >>reason. Why not on all sequence types? > > Because Guido believes that tuples should be primarily used as > lightweight replacements for C structs. Therefore they have minimal > functionality.
I find that a bit contradictory with the fact that if you want list like structures as a dictionary key, you are mostly advised to cast them as tuples. So suppose I want a dictionary, where the keys are colours, represented as RGB triplets of integers from 0 to 255. A number of things can be checked by index-like methods. e.g. def iswhite(col): return col.count(255) == 3 def primary(col): return col.count(255) == 1 and col.count(0) == 2 def secondary(col): return col.count(255) == 2 and col.count(0) == 1 So, what should I use to implement this? Whether I choose lists or tuples, I will end up either copying a lot from lists to tuples or vice versa, to get the functionality I need, or I will have to implement functionality myself that basically is already in the language. I also find the use of C-structs and tuples completly different. If I need a C-struct like object, I go for Bunch, Rec or something similar. Something that uses field identifiers to address components, Not something that uses indexing. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list