[Python-ideas] Sets, Dictionaries

Clint Hepner clint.hepner at gmail.com
Thu Mar 29 15:52:17 EDT 2018


> On 2018 Mar 29 , at 12:06 p, Chris Angelico <rosuav at gmail.com> wrote:
> 
> On Fri, Mar 30, 2018 at 3:00 AM, Stephan Houben <stephanh42 at gmail.com> wrote:
>> Perhaps one day we will be able to use
>> 
>>>> 
>> for the empty set.
>> That would actually match conventional notation.
>> 
> 
> Maybe, but that symbol generally means the unique immutable empty set
> in mathematics, so a closer equivalent would be frozenset(), in the
> same way that () gives you a singleton immutable empty tuple. But yes,
> I would like to some day have a literal for an empty set. Just not
> "{}".
> 

Mathematically, {1,2,3} is a unique, immutable set, too. {1,2,3} \union {4}
doesn't modify {1,2,3}; it's just another way to represent another unique
immutable set {1,2,3,4}. So I don't seen any problem (aside from the general resistance
Unicode) with using ∅ to mean set().

However, just as string literals take a variety of prefixes (r, u, b, f), why can't set/dict literals?

    d{} == {} == dict()
    d{"a": 2} == {"a": 2} == dict(a=2)
    s{1,2,3} == {1,2,3} == set([1,2,3])
    s{} == set()
    f{} == frozenset()
    f{1,2,3} == frozenset({1,2,3})

(I vaguely recall hearing a proposal to use o{...} for ordered dicts, so maybe
this has already been considered. The only information I can find on set literals,
though, assume {...} as a foregone conclusion, with various wrapped symbols like
{/}, {@}, and {:} suggested to complement {}.)

If we did use ∅ for an empty set, then f∅ could be the empty frozen set.

-- 
Clint


More information about the Python-ideas mailing list