[Python-3000] Set literal
Dj Gilcrease
digitalxero at gmail.com
Fri Jan 25 18:06:53 CET 2008
On Jan 24, 2008 8:12 PM, Guido van Rossum <guido at python.org> wrote:
> I hope it isn't too confusing that {1: 1} creates a *mutable* dict
> while {1} creates an *immutable* frozenset. I still find this slightly
> inelegant. But the practicality of being able to treat set literals as
> compile-time constants wins me over.
This probably will not go over well, but why not use the pipe
character to define a frozenset?
if urltxt in |'html', 'xml', 'php'|:
No way to confuse it with a dict, and as far as I know the pipe isnt
used for anything else that would conflict or confuse the issue.
Also on Raymonds point about repr being hard to read
{frozenset([0, 1]): frozenset([frozenset([0]),
frozenset([1]),
frozenset([0, 1, 2])]),
frozenset([0, 1, 2]): frozenset([frozenset([1, 2]),
frozenset([0, 2]),
frozenset([0, 1])])}
would become:
{|0, 1|: ||0|,
|1|,
|0, 1, 2||,
|0, 1, 2|: ||1, 2|,
|0, 2|,
|0, 1||}
More information about the Python-3000
mailing list