Py2.3: Feedback on Sets

Beni Cherniavsky cben at techunix.technion.ac.il
Wed Aug 20 04:10:58 EDT 2003


Raymond Hettinger wrote on 2003-08-17:

> [Beni Cherniavsky]
>
> > And sets of sets (or ImmutableSets as dict keys) are very helpful when you
> > need them.
>
> Good.  I've gotten almost no replies from people using sets of sets.
>
For the record, here is the central data-type of my program
(recognition of lines from a bitmap):

pixel ::= (x, y) tuple
node ::= set of pixels
graph.nodes = {node: set of neighbour nodes} dict
graph.edges = {set of 2 nodes: set of pixels} dict

So I have two dicts, one mapping sets to sets of sets and the other
mapping sets of sets to sets ;-).  The the fact that sets can be
dictionary keys is perhaps even more useful than sets being set
elements.

P.S. I wonder what happens if I do::

    s = Set([1, 2])
    s.add(s)

how badly will operations on it break then?  Perhaps the docs should
mention that circular set structures are a bad idea (see the quote in
my signature ;).

-- 
Beni Cherniavsky <cben at tx.technion.ac.il>

A word of warning about matrices - *each column must have the same
number of elements in it*.  The world will end if you get this wrong.
  -- EQN user manual, Brian W. Kernighan & Lorinda L. Cherry





More information about the Python-list mailing list