frozenset() without arguments should return a singleton

Discussion in 'Python' started by Stefan Behnel, Feb 11, 2005.

  1. Hi!

    frozenset() doesn't behave as the other immutable empty data types in 2.4:

    ..>>> '' is ''
    True
    ..>>> () is ()
    True
    ..>>> frozenset() is frozenset()
    False

    ..>>> id(()),id(())
    (1077579820, 1077579820)
    ..>>> id(())
    1077579820
    ..>>> id(frozenset()),id(frozenset())
    (1077581296, 1077581296)
    ..>>> id(frozenset())
    1077581440
    ..>>> id(frozenset(()))
    1077582256

    frozenset() called without arguments (or on empty sequences) should always
    return a singleton object. It is immutable, so I can see no reason why it
    should take up more resources than necessary.

    Stefan
    Stefan Behnel, Feb 11, 2005
    #1
    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. Stefan Behnel
    Replies:
    2
    Views:
    280
    Stefan Behnel
    Feb 12, 2005
  2. Stefan Behnel
    Replies:
    3
    Views:
    289
    Raymond Hettinger
    Feb 14, 2005
  3. Will McGugan

    frozenset question

    Will McGugan, Jul 6, 2005, in forum: Python
    Replies:
    10
    Views:
    2,251
    George Sakkis
    Jul 7, 2005
  4. Jacob Page

    set and frozenset unit tests?

    Jacob Page, Jul 12, 2005, in forum: Python
    Replies:
    5
    Views:
    304
    Raymond Hettinger
    Jul 15, 2005
  5. Charles Oliver Nutter

    Singleton methods without the singleton class

    Charles Oliver Nutter, Mar 15, 2010, in forum: Ruby
    Replies:
    4
    Views:
    195
    Charles Oliver Nutter
    Mar 22, 2010
Loading...

Share This Page