General question about Python design goals

Antoon Pardon apardon at forel.vub.ac.be
Mon Nov 28 08:17:11 EST 2005


Op 2005-11-28, Duncan Booth schreef <duncan.booth at invalid.invalid>:
> Antoon Pardon wrote:
>
>> 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
>
> Just because you *can* implement these by treating your colour like a list 
> doesn't make it a good idea. Treating them as opaque values makes these 
> particular tests clearer:

You are getting sidetracked. Whether this is the best possible
implementation here is not the issue. This example is just
to illustrate.

I'm sure I could come up with an other example where I would like
to have both some list method and use it as a dictionary key and
again people could start about that implementation having some
flaws and give better implementations.

I'm just illustrating that some list-like methods with tuples
could be usefull.

-- 
Antoon Pardon



More information about the Python-list mailing list