[Tutor] Dictionaries of Tuples of Strings

Terry Carroll carroll at tjc.com
Fri Feb 23 22:41:57 CET 2007

On Fri, 23 Feb 2007, Luke Paireepinart wrote:

> That's because you can't make tuples of single values.
> Think of it like this:
> a TUple needs TWO elements or more.

No, a tuple can also be of one element, or even none.  You can create a
single-element tuple either directly through the use of a trailing comma,
or via the tuple() method:

>>> t = "x",         # but this looks like a syntax error or a continued line
>>> t = ("x",)       # I think this is a little clearer, but still ugly
>>> t = tuple("x")   # my preference

You can also create an empty tuple, but I think only through the tuple() 

>>> t = ,
SyntaxError: invalid syntax
>>> t = (,)
SyntaxError: invalid syntax
>>> t=tuple()
Any other way to create an empty tuple? 

More information about the Tutor mailing list