ways to declare empty set variable

Ben Finney bignose+hates-spam at benfinney.id.au
Wed Feb 13 00:04:35 CET 2008


bearophileHUGS at lycos.com writes:

> For Python 3.0 I'd like {} for the empty set and {:} for the empty
> dict, but that idea was refused time ago, probably for some mental
> backward compatibility.

I agree with not breaking that backward compatibility; it seems
wanton.

> Missing that, I think dict() and set() and tuple() and list()

I often use these myself. They're slightly more explicit, which can
help when I want the reader not to have to think too much, and they're
not particularly verbose because the names are well-chosen and short.

> look better than using {} for the empty dict and {/} for the empty
> set and () for empty tuple

Note that '()' is syntactically null. Parentheses don't declare a
tuple literal, commas do. Parentheses are for grouping within
expressions, not specifying type.

> (or {} for the empty dict and set() for the empty set).

I thought you said above that you preferred 'set()' for an empty set?
I'm not sure what it is you're saying now.

> the only little wart left is the unary tuple literal: x, that I
> don't like much

I agree that it's a wart, but I think the harm done by trying to
change it would be more than the harm done by leaving it in.

-- 
 \     “[W]e are still the first generation of users, and for all that |
  `\      we may have invented the net, we still don’t really get it.” |
_o__)                                                   —Douglas Adams |
Ben Finney



More information about the Python-list mailing list