[Python-ideas] Re: Adding syntax for the empty set

2021-04-10 Thread Stephen J. Turnbull
Chris Angelico writes: > Not to mention everyone's keyboards. Python != APL. Err, I mean, > Python ≠ APL. I am really tired of this argument. set() is not going to go away. And it's easy enough to install input methods (aka "keyboards") on any modern system that allow you to enter these if yo

[Python-ideas] Re: Adding syntax for the empty set

2021-04-10 Thread Guido van Rossum
Please. Use. set(). On Sat, Apr 10, 2021 at 02:03 Serhiy Storchaka wrote: > 09.04.21 19:08, micro codery пише: > > > > You can now use `{*()}` as a syntax for empty set. > > > > I saw that in the ast module and think it's clever, mainly in a good > > way. I don't think it is the same as havi

[Python-ideas] Re: Adding syntax for the empty set

2021-04-10 Thread Serhiy Storchaka
09.04.21 19:08, micro codery пише: > > You can now use `{*()}` as a syntax for empty set. > > I saw that in the ast module and think it's clever, mainly in a good > way. I don't think it is the same as having dedicated syntax for the > empty set partly because I think it needs to be taught. I

[Python-ideas] Re: Adding syntax for the empty set

2021-04-10 Thread Serhiy Storchaka
09.04.21 19:42, Ricky Teachey пише: > On Fri, Apr 9, 2021 at 3:20 AM Serhiy Storchaka > > wrote: > You can now use `{*()}` as a syntax for empty set. > > Interestingly, Raymond Hettinger recently had a post on twitter > specifically deriding this usage as obfuscato

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Skip Montanaro
> > $ def unpack_set(): > > return {*()} > > > $ dis.dis(unpack_set) > 2 0 BUILD_SET0 > 2 LOAD_CONST 1 (()) > 4 SET_UPDATE 1 > 6 RETURN_VALUE > Seems like the peephole optimizer could be trained t

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Jonathan Fine
In August 2020, in the context of PEP 472 I suggested >>> {-} for the empty set literal. At present the closest we can do for an empty set literal is >>> {0} - {0} set() The context for this is whether PEP 472 should make >>> something[] a syntax error. If we do then, what about th

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread David Mertz
On Fri, Apr 9, 2021, 3:23 PM Peter Ludemann wrote: > David Mertz wrote: > > The pattern of "Create an empty collection, then add stuff in a loop" is > quite common, ... > > Or you can use comprehensions, in which case there's no need for creating > an empty collection. > > s = {f(x) for x in some

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Peter Ludemann
David Mertz wrote: > The pattern of "Create an empty collection, then add stuff in a loop" is > quite common, ... Or you can use comprehensions, in which case there's no need for creating an empty collection. s = {f(x) for x in some_list} vs s = set() for x in some_list: s.add(f(x)) __

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Ricky Teachey
On Fri, Apr 9, 2021 at 1:30 PM David Mertz wrote: > I don't do twitter, so hadn't seen Raymond's comment. But I agree that > `{*()}` is too-clever-by-half. Moreover, it's the same character count as > `set()`, so it doesn't even save anything. > > Using five characters to create an empty `set()

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread David Mertz
I don't do twitter, so hadn't seen Raymond's comment. But I agree that `{*()}` is too-clever-by-half. Moreover, it's the same character count as `set()`, so it doesn't even save anything. Using five characters to create an empty `set()` really isn't that many. I do that all the time. Proposals

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Chris Angelico
On Sat, Apr 10, 2021 at 2:44 AM Ricky Teachey wrote: > > On Fri, Apr 9, 2021 at 3:20 AM Serhiy Storchaka wrote: >> >> 08.04.21 19:58, ucod...@gmail.com пише: >> > I would like to propose adding literal syntax to allow creation of an >> > empty set without the need to call the type constructor. I

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Christopher Barker
On Fri, Apr 9, 2021 at 6:06 AM Matt del Valle wrote: > > What I meant to say is that the other comparable builtin types > (comma-delimited containers of some description) that have literals built > into the language (list, tuple, dict) also have a literal that represents > an empty version of the

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Ricky Teachey
On Fri, Apr 9, 2021 at 3:20 AM Serhiy Storchaka wrote: > 08.04.21 19:58, ucod...@gmail.com пише: > > I would like to propose adding literal syntax to allow creation of an > empty set without the need to call the type constructor. I believe the best > choice for such a literal, and one that has be

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread micro codery
> > > You can now use `{*()}` as a syntax for empty set. > > I saw that in the ast module and think it's clever, mainly in a good way. I don't think it is the same as having dedicated syntax for the empty set partly because I think it needs to be taught. I don't think a new pythonista would turn to

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Matt del Valle
Sorry, I really should have had my morning coffee before making that reply. Big-time thinko :) What I meant to say is that the other comparable builtin types (comma-delimited containers of some description) that have literals built into the language (list, tuple, dict) also have a literal that rep

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Serhiy Storchaka
09.04.21 12:50, Matt del Valle пише: > I think sets are the only type in the builtins module > without a dedicated literal syntax? Not only. bytearray, frozenset, slice. It is difficult to create some complex objects without using constructor. Not counting range, memoryview and dict views, descrip

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Matt del Valle
Oh god, Stephane, you're giving me flashbacks to PEP 3117 ( https://www.python.org/dev/peps/pep-3117/). But not in a good way. Please pretty please let's keep unicode characters out of our code. With regards to the original proposal, for what it's worth, I like it well enough. I think sets are th

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Chris Angelico
On Fri, Apr 9, 2021 at 6:09 PM Stéfane Fermigier wrote: > > I think the best alias for "empty set" would be the Unicode character "Empty > set" or U+2205, i.e. "∅". > > Alas, it's not a valid identifier in Python: > > >>> ∅ = set() > File "", line 1 > ∅ = set() > ^ > SyntaxError: invali

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Stéfane Fermigier
I think the best alias for "empty set" would be the Unicode character "Empty set" or U+2205, i.e. "∅". Alas, it's not a valid identifier in Python: >>> ∅ = set() File "", line 1 ∅ = set() ^ SyntaxError: invalid character '∅' (U+2205) It works with the similarly looking "ϕ" or 'GREEK PH

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Serhiy Storchaka
08.04.21 19:58, ucod...@gmail.com пише: > I would like to propose adding literal syntax to allow creation of an empty > set without the need to call the type constructor. I believe the best choice > for such a literal, and one that has been proposed before, is `{,}`. You can now use `{*()}` as a