> > > 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 empty tuple unpacking to get the empty set, where I do think that either set() or {,} would be natural, at least after some trial and exceptions. It also doesn't give quite the optimization as {,}. $ def comma_set(): > return {,} > $ dis.dis(comma_set) 2 0 BUILD_SET 0 2 RETURN_VALUE $ def unpack_set(): > return {*()} > $ dis.dis(unpack_set) 2 0 BUILD_SET 0 2 LOAD_CONST 1 (()) 4 SET_UPDATE 1 6 RETURN_VALUE although it is better than recommendations I have seen for 2.7 code $ def and_set(): > return {1} & {2} > $ dis.dis(and_set) 2 0 LOAD_CONST 1 (1) 2 BUILD_SET 1 4 LOAD_CONST 2 (2) 6 BUILD_SET 1 8 BINARY_AND 10 RETURN_VALUE
Part of the problem here might be the teaching; if {*()} had been talked about since 3.0 and pointed out in documentation and tutorials I likely would never have thought to raise this proposal. But I don't think it is well known, and not often used. I gave examples of where in cpython set() is used, however {*()} is only used once, as a string in ast.py; not even set repr uses this fancy syntax but instead returns "set()" for the empty set, even though braces are used to repr sets of any non-zero length.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/T4P5QV5TLLLPCBYLAZ57AYRDJM3JWHXI/ Code of Conduct: http://python.org/psf/codeofconduct/