Dual look-up on keys?

Micah Cowan micah at cowan.name
Thu Mar 6 06:03:47 CET 2008


castironpi at gmail.com writes:

> On Mar 5, 8:03 pm, castiro... at gmail.com wrote:
>> On Mar 5, 5:31 pm, Grant Edwards <gra... at visi.com> wrote:
>>
>> > On 2008-03-05, castiro... at gmail.com <castiro... at gmail.com> wrote:
>> > > Anyway, if (a,b) is a key in dictionary d, can it guarantee
>> > > that (b,a) is also in it, and maps to the same object?
>>
>> Er... -specialized- dictionary d.
>>
>> > To solve that problem, Python provides the immutable
>> > "frozenset" type:
>>
>> >   >>> s1 = frozenset((1,2))
>> >   >>> s2 = frozenset((2,1))
>> >   >>> s1 == s2
>> >   True
>> >   >>> d = {s1: "hi there"}
>> >   >>> s1 in d
>> >   True
>> >   >>> s2 in d
>> >   True
>>
>> Ah.  Perfect.  With this, I can just call frozenset on keys in
>> __setitem__ and __getitem__... (though at that, it may be easier
>> verbatim*.)
>
>> a= SomeList( [ 1,2,3 ] )
>> b= SomeList( [ 1,2,3 ] )
>> assert a is not b
>> d[a]= True
>> assert b not in d
>> #there's the hangup
>
> *plonk*
>
> key is an iterable, just like the constructors to <bleep bl bbl bleep>
> other collection.

Um... "*plonk*" is the (imaginary) sound made by dropping someone into
your plonkfile (killfile, scorefile, whatever): the action of setting
your newsreader to ignore someone you perceive to be a troll.

I have extreme doubts that you have actually done this to _yourself_.

-- 
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/



More information about the Python-list mailing list