When are immutable tuples *essential*? Why can't you just use lists *everywhere* instead?
Steven D'Aprano
steve at REMOVE.THIS.cybersource.com.au
Fri Apr 20 22:16:44 EDT 2007
On Fri, 20 Apr 2007 15:53:45 -0700, garrickp wrote:
> Speaking of inessential but very useful things, I'm also a big fan of
> the tuple swap...
> a = 2
> b = 3
> (a, b) = (b, a)
Since tuples are made by commas, not brackets, that can be written more
cleanly as:
a, b = b, a
The only exception is the special case of an empty tuple, which can be
written as ().
> IMO, the biggest thing going for tuples is the syntactical sugar they
> bring to Python.
More important than the ability to use them as keys in dicts?
--
Steven.
More information about the Python-list
mailing list