from Hacker News

Adding Empty Set Literals to Python

by philipbjorge on 3/16/13, 3:06 AM with 46 comments

  • by rakha on 3/16/13, 6:18 AM

    "I thought {@} would be a good for an empty set because it arguably looks like the empty set symbol"

    I'm just nitpicking but I don't think this is a good justification - If the @ symbol looks like the empty set symbol, then {@} is the set containing the empty set

  • by jrockway on 3/16/13, 8:11 AM

    I personally prefer dict() to {} anyway, so I don't really miss the lack of an empty set literal.

    Adding a set literal was a slippery slope anyway. Where's my frozenset literal? Where's my namedtuple literal?

    (I also don't particularly like the {} syntax for dicts, because there is {'too_much': 'quoting'} which I find rather ugly. I much prefer dict(too_much='quoting') or, even better, Perl's solution: { too_much => 'quoting' }.)

  • by raymondh on 3/16/13, 5:36 AM

    Executive summary: If you don't like part of the language, it is really easy to add your own hack and make it worse ;-)

    Really, you should trust the core developers on this one. Empty set literals are missing from Python for a reason.

  • by polemic on 3/16/13, 7:30 AM

    That ain't orthogonality, this is orthogonality:

        dict() = {}
        set() = <>
        tuple() = ()
        list() = []
    
    (btw, does anyone actually use `<>` as `!=`?)
  • by hwiechers on 3/16/13, 7:05 AM

    I think it would be best if empty dictionary was {:} and empty set was {}. Of course, it would be insane to make this change.
  • by sciencerobot on 3/16/13, 3:52 AM

    Maybe Guido doesn't like it because it looks weird when compared to the rest of Python's syntax? Still, I think it's cool. Having sets availably without importing anything is one of the things I love about Python.

    set = <> is still available.

  • by codesuela on 3/16/13, 3:20 PM

    The webfont doesn't load for me because I have Ghostery installed (it blocks remote tracking scripts) so the page is all blank except for the code snippets (because Adobe Typekit is blocked). You should consider adding a fallback font.
  • by vbtemp on 3/16/13, 1:32 PM

    > What I learned: It’s not always hard to make interesting changes to large projects.

    Should be, it's not always hard to make interesting changes to very well-designed and well-architected projects

  • by johnsoft on 3/16/13, 4:33 AM

    I vaguely recall seeing a mailing list thread where `{-}` was proposed. I think it was rejected based on parsing ambiguity, i.e. `{-1}` vs `{-}`. (Or it's possible I might be losing my memory)
  • by tantalor on 3/16/13, 5:19 AM

        There should be one-- and preferably only one --obvious way to do it.
        Although that way may not be obvious at first unless you're Dutch.
  • by SilasX on 3/16/13, 4:11 AM

    Is it just me, or is it a little ... obsessive to be this annoyed with having to use `set()` instead of `{@}`?