General question about Python design goals

bonono at gmail.com bonono at gmail.com
Thu Dec 1 02:55:52 EST 2005


Mike Meyer wrote:
> I get all that, I really do. I would phrase it as "a tuple is a set of
> attributes that happen to be named by integers." count doesn't make
> sense on the attributes of an object - so it doesn't make sense on a
> tuple. index doesn't make sense on the attributes of an object - so it
> doesn't make sense on a tuple. A loop over the attributes of an object
> doesn't make sense - so it doesn't make sense on a tuple.
>
> So why the $*@& (please excuse my Perl) does "for x in 1, 2, 3" work?
>
> Seriously. Why doesn't this have to be phrased as "for x in list((1,
> 2, 3))", just like you have to write list((1, 2, 3)).count(1), etc.?
>
I don't know what you use tuple for, but I do need to loop over
attributes of an object(be it tuple or dict or even set), though no
need for count(), index(), not even on list, so far.

I think why people may ask for .count() and .index() for tuple is that
if I am writing a generic function that receive such a thing, I don't
need to do a type check or try/except block, should the caller tries to
be smart and use tuple instead of list(say for optimization reason).




More information about the Python-list mailing list