ways to declare empty set variable

Boris Borcic bborcic at gmail.com
Sat Feb 16 11:05:08 CET 2008

bearophileHUGS at lycos.com wrote:
> ...Missing that, I think dict() and set() and
> tuple() and list() look better than using {} for the empty dict and
> {/} for the empty set and () for empty tuple (or {} for the empty dict
> and set() for the empty set).

The problem I have with them is in no way the looks, it is that they are not 
strictly equivalent as they imply dictionary lookups. Which shows in performance, eg

 >>> import timeit
 >>> timeit.Timer('[]').timeit()
 >>> timeit.Timer('list()').timeit()
 >>> timeit.Timer('{}').timeit()
 >>> timeit.Timer('dict()').timeit()

Cheers, BB

More information about the Python-list mailing list