[Python-3000] sets in P3K?

Barry Warsaw barry at python.org
Wed Apr 26 14:25:42 CEST 2006


On Wed, 2006-04-26 at 08:03 +0000, Talin wrote:

> 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.

I agree that empty sets are created much more often than filled sets,
and I have no problem writing "set()" for that.  I have very
occasionally written a pre-filled set, and the only thing about that is
that the TypeError resulting from "set(1, 2, 3)" is at first confusing.
But it's one of those things you 'get' after the first trip-up so again,
I think it's fine.

I forgot who wrote yesterday about literal notation being "about right"
in Python 2, and I agree.  List, tuple, and dict literals are one of the
things that make Python Python.  No reason to get rid of those, and I
don't think filled-sets are common enough to warrant literal notation.

> 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.)

Very interesting.  That's probably the primary reason why I've started
preferring dict(...) over {...}.  Of course it only works when your keys
are identifier-like strings.

-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 309 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-3000/attachments/20060426/688aee77/attachment.pgp 


More information about the Python-3000 mailing list