PEP218: Representing the empty set

Peter Hansen peter at engcorp.com
Tue Feb 17 22:03:47 CET 2004


Andrew McLean wrote:
> 
> Looking at PEP218 there is a discussion about the most appropriate way
> of representing the empty set. The two alternatives proposed are {} and
> {-}. I was wondering why either of these is needed. Why not just use
> set()?. It is only two more characters than {-} and a bit more explicit.
> 
> Similarly, I find myself initialising dictionaries with dict() rather
> than {}.
> 
> Am I missing something?

Maybe it's nothing more than this distinction:  dict() is a call which
*returns* an empty dictionary.  {} *is* an empty dictionary.  Likewise,
set() returns an empty set, which presumably {-} directly *is* an empty
set.

As someone not involved in the participation, I don't know how much
value my observation has, but to me it looks like a question of readability.
The direct representation flows better than the function call/constructor
approach...

-Peter



More information about the Python-list mailing list