Re: Set of Dictionary

Discussion in 'Python' started by Konstantin Veretennicov, Jun 16, 2005.

  1. On 6/16/05, Vibha Tripathi <> wrote:
    > I need sets as sets in mathematics:


    That's tough. First of all, mathematical sets can be infinite. It's
    just too much memory :)
    Software implementations can't fully match mathematical abstractions.

    > sets of any unique type of objects including those
    > of dictionaries, I should then be able to do:
    > a_set.__contains__(a_dictionary) and things like that.


    Maybe you can use a list for that:

    >>> d1 = {1: 2}
    >>> d2 = {3: 4}
    >>> s = [d1, d2]
    >>> {1: 2} in s

    True
    >>> {5: 6} in s

    False

    > Can sets in Python 2.4.1, be reimplemented from
    > scratch to not have it work on top of dict?


    Sure, why not?

    - kv
     
    Konstantin Veretennicov, Jun 16, 2005
    #1
    1. Advertising

  2. On Thu, 16 Jun 2005 21:21:50 +0300, Konstantin Veretennicov wrote:

    > On 6/16/05, Vibha Tripathi <> wrote:
    >> I need sets as sets in mathematics:

    >
    > That's tough. First of all, mathematical sets can be infinite. It's
    > just too much memory :)
    > Software implementations can't fully match mathematical abstractions.


    :)

    But lists can be as long as you like, if you have enough memory. So
    can longs and strings. So I don't think the infinity issue is a big one.

    >> sets of any unique type of objects including those
    >> of dictionaries, I should then be able to do:
    >> a_set.__contains__(a_dictionary) and things like that.


    Standard Set Theory disallows various constructions, otherwise you get
    paradoxes.

    For example, Russell's Paradox: the set S of all sets that are not an
    element of themselves. Then S should be a set. If S is an element of
    itself, then it belongs in set S. But if it is in set S, then it is an
    element of itself and it is not an element of S. Contradiction.

    The price mathematicians pay to avoid paradoxes like that is that some
    sets do not exist. For instance, there exists no universal set (the set
    of all sets), no set of all cardinal numbers, etc.

    So even in mathematics, it is not true that sets can contain anything.


    > Maybe you can use a list for that:
    >
    >>>> d1 = {1: 2}
    >>>> d2 = {3: 4}
    >>>> s = [d1, d2]
    >>>> {1: 2} in s

    > True
    >>>> {5: 6} in s

    > False
    >
    >> Can sets in Python 2.4.1, be reimplemented from
    >> scratch to not have it work on top of dict?

    >
    > Sure, why not?


    Take a close look at the sets module, written in Python. You could copy
    and modify the source code (taking care to obey whatever licencing
    restrictions, if any, there are).



    --
    Steven
     
    Steven D'Aprano, Jun 17, 2005
    #2
    1. Advertising

  3. [offtopic] Re: Set of Dictionary

    Steven D'Aprano wrote:

    > On Thu, 16 Jun 2005 21:21:50 +0300, Konstantin Veretennicov wrote:
    >
    >
    >>On 6/16/05, Vibha Tripathi <> wrote:
    >>
    >>>I need sets as sets in mathematics:

    >>
    >>That's tough. First of all, mathematical sets can be infinite. It's
    >>just too much memory :)
    >>Software implementations can't fully match mathematical abstractions.

    >
    >
    > :)
    >
    > But lists can be as long as you like, if you have enough memory.


    But you never have enough memory to store, for example,
    a list of all the prime integers (not using a regular list,
    anyway).

    > So
    > can longs and strings. So I don't think the infinity issue is a big one.
    >
    >
    >>> sets of any unique type of objects including those
    >>>of dictionaries, I should then be able to do:
    >>>a_set.__contains__(a_dictionary) and things like that.

    >
    >
    > Standard Set Theory disallows various constructions, otherwise you get
    > paradoxes.
    >
    > For example, Russell's Paradox: the set S of all sets that are not an
    > element of themselves. Then S should be a set. If S is an element of
    > itself, then it belongs in set S. But if it is in set S, then it is an
    > element of itself and it is not an element of S. Contradiction.
    >
    > The price mathematicians pay to avoid paradoxes like that is that some
    > sets do not exist. For instance, there exists no universal set (the set
    > of all sets), no set of all cardinal numbers, etc.
    >
    > So even in mathematics, it is not true that sets can contain anything.


    See "Set Theory With a Universal Set" by T. Forster, which covers
    some set theories in which there *is* a set of all things, and
    in which Russell's paradox is avoided in other ways (such as by
    restricting the comprehension axioms).

    (Sorry for drifting offtopic, I happen to find non-standard
    set theories interesting and thought that some others here
    might too.)

    -- James
     
    James Dennett, Jun 26, 2005
    #3
  4. Re: [offtopic] Re: Set of Dictionary

    James Dennett said unto the world upon 26/06/2005 03:51:
    > Steven D'Aprano wrote:
    >
    >
    >>On Thu, 16 Jun 2005 21:21:50 +0300, Konstantin Veretennicov wrote:
    >>
    >>
    >>
    >>>On 6/16/05, Vibha Tripathi <> wrote:
    >>>
    >>>
    >>>>I need sets as sets in mathematics:
    >>>
    >>>That's tough. First of all, mathematical sets can be infinite. It's
    >>>just too much memory :)
    >>>Software implementations can't fully match mathematical abstractions.

    >>
    >>
    >>:)
    >>
    >>But lists can be as long as you like, if you have enough memory.

    >
    >
    > But you never have enough memory to store, for example,
    > a list of all the prime integers (not using a regular list,
    > anyway).



    An even better example is the set of reals in the interval (0, 1).
    Even an idealized Turing machine with (countably) infinite memory will
    choke on that :)

    <snip>


    >>Standard Set Theory disallows various constructions, otherwise you get
    >>paradoxes.
    >>
    >>For example, Russell's Paradox: the set S of all sets that are not an
    >>element of themselves. Then S should be a set. If S is an element of
    >>itself, then it belongs in set S. But if it is in set S, then it is an
    >>element of itself and it is not an element of S. Contradiction.
    >>
    >>The price mathematicians pay to avoid paradoxes like that is that some
    >>sets do not exist. For instance, there exists no universal set (the set
    >>of all sets), no set of all cardinal numbers, etc.
    >>
    >>So even in mathematics, it is not true that sets can contain anything.

    >
    >
    > See "Set Theory With a Universal Set" by T. Forster, which covers
    > some set theories in which there *is* a set of all things, and
    > in which Russell's paradox is avoided in other ways (such as by
    > restricting the comprehension axioms).
    >
    > (Sorry for drifting offtopic, I happen to find non-standard
    > set theories interesting and thought that some others here
    > might too.)
    >
    > -- James



    So do I :)

    Do you know of non-well-founded set theory (non-standard set theory
    which allows sets A, such that A is in A)? Not really on point for any
    of the above, but being on topic is in the rear view mirror, anyway :)

    <http://cslipublications.stanford.edu/site/1575860082.html>
    <http://cslipublications.stanford.edu/site/0937073229.html>

    Best,

    Brian vdB
     
    Brian van den Broek, Jun 26, 2005
    #4
    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. Ilias Lazaridis
    Replies:
    6
    Views:
    455
    Ilias Lazaridis
    Feb 21, 2006
  2. james_027
    Replies:
    1
    Views:
    338
    Marc 'BlackJack' Rintsch
    Aug 22, 2007
  3. Navkirat Singh
    Replies:
    6
    Views:
    3,166
    Navkirat Singh
    Jul 29, 2010
  4. Chris Rebert
    Replies:
    0
    Views:
    541
    Chris Rebert
    Jul 29, 2010
  5. Fox

    dictionary within dictionary

    Fox, Mar 8, 2005, in forum: ASP General
    Replies:
    5
    Views:
    199
    Michael D. Kersey
    Mar 13, 2005
Loading...

Share This Page