set using alternative hash function?

Rami Chowdhury rami.chowdhury at gmail.com
Thu Oct 15 18:24:18 CEST 2009


On Thu, 15 Oct 2009 09:11:00 -0700, Austin Bingham  
<austin.bingham at gmail.com> wrote:

> On Thu, Oct 15, 2009 at 5:15 PM, Gabriel Genellina
> <gagsl-py2 at yahoo.com.ar> wrote:
>> En Thu, 15 Oct 2009 11:42:20 -0300, Austin Bingham
>> <austin.bingham at gmail.com> escribió:
>> I think you didn't understand correctly Anthony Tolle's suggestion:
>>
>> py> class Foo:
>> ...   def __init__(self, name): self.name = name
>> ...
>> py> objs = [Foo('Joe'), Foo('Jim'), Foo('Tom'), Foo('Jim')]
>> py> objs
>
> I understand Anthony perfectly. Yes, I can construct a dict as you
> specify, where all of the keys map to values with name attributes
> equal to the key. My point is that dict doesn't really help me enforce
> that beyond simply letting me set it up; it doesn't care about the
> values at all, just the keys.

Perhaps this is an overly naive solution, but could you not define a class  
that implemented the set interface but used a dict for internal storage,  
and use that? You'd still have uniqueness (by dict key, which your class  
would define as object name) and as a bonus, retrievability by name, which  
set wouldn't give you.


-- 
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)



More information about the Python-list mailing list