On 5/6/20 3:04 AM, Greg Ewing wrote: > On 6/05/20 1:58 pm, Henk-Jaap Wagenaar wrote: >> I'd say the difference is just one of semantics and as a >> mathematician I would consider tuples and sequences as "isomorphic", >> in fact, the set-theoretical construction of tuples as functions is >> *identical* to the usual definition of sequences: i.e. they are just >> two interpretations of the the same object depending on your point of >> view. > > Maybe the small subset of mathematicians that concern themselves > with trying to define everything in terms of sets, but I don't > think the majority of mathematicians think like that in their > everyday work. It's certainly at odds with the way I see tuples > and sequences being used in mathematics. > > As well as the same type vs. different types thing, here are > some other salient differences: > > - Infinite sequences make sense, infinite tuples not so much. > > - Sequences are fundamentally ordered, whereas tuples are not > ordered in the same sense. Any apparent ordering in a tuple is > an artifact of the way we conventionally write them. If we were > in the habit of labelling the elements of a tuple and writing > things like (x:1, y:2, z:3) then we wouldn't have to write them > in any particular order -- (y:2, x:1, z:3) would be the same > tuple. > In my mind, tuples and lists seem very different concepts, that just happen to work similarly at a low level (and because of that, are sometimes 'misused' as each other because it happens to 'work').
To me, tuples are things when the position of the thing very much matters, you understand the meaning of the Nth element of a tuple because it IS the Nth element of the tuple. It isn't so important that the Nth is after the (N-1)th element, so we could define our universe of tuples in a different order then it might still make sense, but we then need to reorder ALL the tuples of that type. A coordinate makes a great example of a tuple, we think of the 1st element of the coordinate as 'X' due to convention, and in the tuple it gets in meaning from its position in the tuple. A list on the other hand is generally not thought of in that way. A list might not be ordered, or it might be, and maybe there is SOME value in knowing that an item is the Nth on the list, but if it is an ordered list, it is generally more meaningful to think of the Nth item in relation to the (N-1)th and (N+1)th items. Adding an element to a tuple generally doesn't make sense (unless it is transforming it to a new type of tuple, like from 2d to 3d), but generally adding an item to a list does. This makes their concepts very different. Yes, you might 'freeze' a list by making it a tuple so it becomes hashable, but then you are really thinking of it as a 'frozen list' not really a tuple. And there may be times you make a mutable tuple by using a list, but then you are thinking of it as a mutable tuple, not a list. And these are exceptional cases, not the norm. -- Richard Damon _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XJSZTXSSUZYE723NDWA3YLNZPQQ2ZCZ4/ Code of Conduct: http://python.org/psf/codeofconduct/