Re: Py2.3: Feedback on Sets

Discussion in 'Python' started by Beni Cherniavsky, Aug 20, 2003.

  1. 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 <>

    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
    Beni Cherniavsky, Aug 20, 2003
    #1
    1. Advertising

  2. On Wed, 20 Aug 2003 11:10:58 +0300 (IDT), rumours say that Beni
    Cherniavsky <> might have written:

    >P.S. I wonder what happens if I do::
    >
    > s = Set([1, 2])
    > s.add(s)
    >
    >how badly will operations on it break then?


    They won't. Sets are mutable, so adding a Set to itself actually adds
    an ImmutableSet copy constructed on the fly.
    --
    TZOTZIOY, I speak England very best,
    Microsoft Security Alert: the Matrix began as open source.
    Christos TZOTZIOY Georgiou, Aug 22, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond Hettinger

    Py2.3: Feedback on Sets

    Raymond Hettinger, Aug 12, 2003, in forum: Python
    Replies:
    21
    Views:
    686
    Christos TZOTZIOY Georgiou
    Aug 20, 2003
  2. Delaney, Timothy C (Timothy)

    RE: Py2.3: Feedback on Sets

    Delaney, Timothy C (Timothy), Aug 14, 2003, in forum: Python
    Replies:
    3
    Views:
    323
    Gary Feldman
    Aug 18, 2003
  3. David Mertz

    Re: Py2.3: Feedback on Sets (fwd)

    David Mertz, Aug 16, 2003, in forum: Python
    Replies:
    10
    Views:
    517
    David Mertz
    Aug 18, 2003
  4. Beni Cherniavsky

    Re: Py2.3: Feedback on Sets

    Beni Cherniavsky, Aug 17, 2003, in forum: Python
    Replies:
    10
    Views:
    546
    Seo Sanghyeon
    Aug 28, 2003
  5. Holger Joukl

    py2.1->py2.3.3 __getattr__ confusion

    Holger Joukl, Jul 2, 2004, in forum: Python
    Replies:
    1
    Views:
    298
    Peter Otten
    Jul 2, 2004
Loading...

Share This Page