Does anybody else find {:}
and {}
be a more natural way to construct empty dictionary and empty set as compared to {}
and set()
? Thanks.
views:
158answers:
4It's not really backward-compatible - {}
is already used everywhere. As everybody is used to the existing syntax, I wouldn't say {:}
is a more natural way of constructing a dictionary (having a short form for empty sets would be nice, but set()
isn't too verbose, either).
- Not really, personally.
{}
has too long a history as an empty dict literal and while I see where you are coming from,{:}
shouldn't really mean empty dict. - 3.3 would not be the right target version for this change. This would break backwards compatibility in a nontrivial way, which is not supposed to happen. (If it ever does, that should be Python 4.0.) This is especially not the proper target version since Python is currently under a syntax-change moratorium.
It seems sensible enough, but that probably isn't enough to justify breaking backward compatiblity.
Perhaps if it was accepted for Python4 there could be a from __future__
to change the behaviour of {}
in Python3 at a per module level.
Having {:}
create empty dicts in the meantime would probably not be too harmful
Not really. You'd still have an ugly special case in the syntax, just move the specialness from the empty set
to the empty dict
.
The logical solution would be to change either set
or dict
to use different brackets. But to what? ( )
and [ ]
are already taken.
And such a backwards-incompatible change wouldn't be approved for 3.3. You'd have to wait for 4.0.