ANN: Set-like methods on dicts

Beni Cherniavsky cben at techunix.technion.ac.il
Tue Jun 10 07:03:25 EDT 2003


John J. Lee wrote on 2003-06-10:

> Beni Cherniavsky <cben at techunix.technion.ac.il> writes:
>
> > Dictionary users of the Python world, unite (or intersect)!
> [...]
>
> They already did:
>
> http://www.python.org/doc/2.3b1/whatsnew/node2.html
>
No, they did not - not with values:

>>> from dsets import *
>>> s =	DSet({1: 'one',	2: 'two'})
>>> s.intersection([1, 5], collision=first)
DSet({1: 'one'})
>>> s.union_update({2:	'TWO', 3: 'THREE'}, collision=second)
>>> s
DSet({1: 'one', 2: 'TWO', 3: 'THREE'})
>>> s.intersection({1: 'one', 2: 'QuuX', 3: 'three'}, collision=str.__eq__)
DSet({1: True, 2: False, 3: False})

How do you do this with sets?  The keys will behave the same with sets
but the values won't be tracked.

-- 
Beni Cherniavsky <cben at users.sf.net>






More information about the Python-list mailing list