ways to declare empty set variable

Boris Borcic bborcic at gmail.com
Sat Feb 16 05:05:08 EST 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()
0.22358344426456436
 >>> timeit.Timer('list()').timeit()
0.54574505977715049
 >>> timeit.Timer('{}').timeit()
0.21328632549668214
 >>> timeit.Timer('dict()').timeit()
0.50557906102591232

Cheers, BB




More information about the Python-list mailing list