2 ms·
The quote comes from Guido van Rossum almost verbatim so that may be a good place to start if you want to dig deeper. As I've also seen, a good rephrasing is t
by wahnfrieden 13y ago
The quote comes from Guido van Rossum almost verbatim so that may be a good place to start if you want to dig deeper.
As I've also seen, a good rephrasing is that lists have order whereas tuples have structure. Yet another mnemonic I've heard that seems apt is that tuples are appropriate where a named-tuple could also conceivably be used.
- beambot 13y agoThat's crazy-interesting and seems like a very good rule of thumb. I've been using Python for a very long time and had never heard this. Why is it not in the PEP?!
- wahnfrieden 13y agoWhich PEP, PEP-8? That's only a style guide. It's included in the stdlib documentation on data structures: http://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences http://docs.python.org/2/tutorial/datastructures.html#tuples...
- dalke 13y agoThe quote is "Tuples are for heterogeneous data, list are for homogeneous data. Tuples are not read-only lists." Guido van Rossum March 12, 2003 in python-dev. However, don’t treat Guido’s statement as a mandate! "Yes, taking Guido too seriously can have that effect on people <1.1 wink> The trick is in knowing when Guido is proscribing dogmatic law, and when he is describing his intent when he designed feature(tte)s of Python, or his point of view at this moment, or how he wished people would see it, or reacting to what he had for lunch. He's just human, you know, and no more infallible than the best of us." Thomas Wouters March 12, 2003 in python-dev For example, consider object.__class__.__bases__. That's a tuple of homogenous data. It's not of a fixed length, and the base class at a given position has no intrinsic name, other than "first", "second", etc. Do you think the use of tuple here is a bug? Should it be a list instead?
- wahnfrieden 13y agoGreat follow-up, thanks! It's not a clear and consistent law, or law at all, you're right.