ways to declare empty set variable

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Feb 16 05:45:40 EST 2008


On Sat, 16 Feb 2008 05:21:22 -0500, Steve Holden wrote:

> Before you have any code is exactly the *wrong* time to be considering
> performance.

Well, not really.

Don't we already tell people "don't use repeated string concatenation, 
because it is slow", even *before* we know whether it is a bottleneck in 
their program or not?

The problem occurs when people make "fastest" the *only* consideration, 
instead of just one out of many. For instance, {} and dict() are very 
different. Consider this:


>>> from collections import defaultdict as dict
>>> D1 = dict()
>>> D2 = {}

They not only have different performance, but different semantics. If you 
consider it desirable to shadow such built-ins or not is open to debate, 
although consider this:

>>> try:
...     set
... except NameError:
...     from sets import Set as set
...
>>> x = set()

You can't do that with syntax.


-- 
Steven



More information about the Python-list mailing list