[Python-3000] sets in P3K?
Talin
talin at acm.org
Wed Apr 26 10:03:18 CEST 2006
Aahz <aahz <at> pythoncraft.com> writes:
>
> On Tue, Apr 25, 2006, Brett Cannon wrote:
> >
> > I'll toss in my straw; I have no issue losing listcomps and favoring
> > ``list(genexp)``. TOOWTDI since there is not that huge of a "simple
> > over complex" savings. Probably never thought about this since I
> > really got into Python when listcomps were introduced so they happen
> > to be heavily ingrained into my Python psyche.
>
> There are [at least] two separate issues being discussed here, and I
> think that's confusing things. From my POV, the issue about whether
> listcomps per se go away in Python 3.0 is completely separate from the
> issue of whether sets get special literal syntax.
>
> My opinion: if we were designing Python from scratch right now, we might
> well consider having only set literals and not dict literals. However,
> I don't think we can have both set and dict literals, and I think that
> removing dict literals (or list literals) counts as gratuitous breakage.
>
> Losing listcomps won't be a big problem because they can be automatically
> fixed and they aren't much loss.
In my experience dict literals are far more useful than set literals. In fact, I
don't think I've ever made a set literal. The only syntactical short cut that I
would find useful for a set would be "new empty set", for which I think "set()"
is probably short enough already.
As someone stated earlier, sets are most often built up incrementally, or are
the result of a transformation of other data. Dicts, on the other hand, are very
frequently specified in literal form.
I think that the syntactical shortcuts we have for Python are just right - if I
were to start over, I doubt I would change anything. Part of the big win that
scripting languages have over statically compiled languages such as C++ is their
ability to declare complex, dynamic data structures as literals; Syntactic
shortcuts make that strength even stronger. And Python takes the 3 most commonly
used container types - dicts, tuples, and lists - and gives them easy-to-type
shortcuts.
Actually, there is *one* thing that I would change about the current syntax,
which is that I would change dict literals to have the same internal syntax as
function calls, so that { <something> } would be equivalent to dict( <something>
). This means using '=' instead of ':' and allowing key names to be bare words
instead of quoted strings. So you could write:
{ name="Frodo", race="Hobbit" }
instead of:
{ 'name':'Frodo', 'race':'Hobbit' }
(Only 4 characters longer, but *much* harder to type. Try typing it if you don't
believe me.)
-- Talin
More information about the Python-3000
mailing list