[Python-3000] sets in P3K?

Alex Martelli aleaxit at gmail.com
Wed Apr 26 16:43:15 CEST 2006


On Apr 26, 2006, at 5:19 AM, Barry Warsaw wrote:

> On Tue, 2006-04-25 at 15:48 -0700, Aahz wrote:
>
>> 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.
>
> Agreed.  The current status quo seems fine.
>
> Losing listcomps won't be a big problem because they can be  
> automatically
>> fixed and they aren't much loss.
>
> Totally half-baked way-pre-morning-coffee thought: isn't
>
> [f(x) for x in seq]
>
> just another way to spell
>
> list(genexp) where genexp == f(x) for x in eq?
>
> So, if there are no list comps any more, but list literal notation  
> could
> take a genexp, doesn't that give us today's syntactic convenience with
> tomorrow's consistence world view?

If I read you right, that is exactly the reason I would prefer that  
Python 3k *NOT* have both notations that work today, i.e.:
     [ f(x) for x in seq ]
as an exact synonym of
     list( f(x) for x in seq )

Today, among the reasons for preferring the list(...<genexp>...) form  
is that it doesn't leak name x into the enclosing scope.  But even  
once py3k fixes that leakage, the list(...) form remains IMHO more  
readable -- and nobody's proposing to take it away, in any case, so  
the "one obvious way" mantra suggest taking away the alternate [...]  
syntax instead.

Among other things, this will place lists, sets and other (builtin or  
user-coded) collection types on even syntactic footing for  
comprehension purposes:
     list( f(x) for x in seq )
     set( f(x) for x in seq )
     deque( f(x) for x in seq )
     ...
rather than singling one or two types out for special, different  
alternative comprehension syntax.


On literals as opposed to comprehensions I have no strong opinions,  
although I don't think the status quo is actually ``fine'' (it IS a  
tiny bother, but a bother nevertheless, to have to write set 
((23,42,77)) vs [23, 42, 77]...!), neither is it "badly broken". In  
fact the most common beginner error in writing literals is using (23)  
instead of (23,) when trying to make a singleton tuple, and I have no  
great idea on how to fix that, anyway;-).


Alex



More information about the Python-3000 mailing list