Re: Tuples vs Lists: Semantic difference
Ben Finney wrote: Bjoern Schliessmann [EMAIL PROTECTED] Explain. Well, since you ask so politely :-) I admit, sometimes I'm a little short-spoken ;) I know tuples as immutable lists ... That's a common misconception. [...] Thanks for pointers, there's more to it than I suspected. Regards, Björn -- BOFH excuse #384: it's an ID-10-T error -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuples vs Lists: Semantic difference (was: Extract String From Enclosing Tuple)
George Sakkis, I agree with the things you say. Sometimes you may have a sequence of uniform data with unknown len (so its index doesn't have semantic meaning). You may want to use it as dict key, so you probably use a tuple meant as just an immutable list. I don't know Ruby, but I think it allows such purposes with a freezing function. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuples vs Lists: Semantic difference (was: Extract String From Enclosing Tuple)
On Mar 1, 5:02 am, [EMAIL PROTECTED] wrote: I don't know Ruby, but I think it allows such purposes with a freezing function. In ruby all objects can be frozen (freeze is a method on Object, from which all other objects derive), not just Arrays (Arrays == lists in python; ruby has no built-in container equiv. to tuple). But that's more of an implementation detail rather than anthing to do with the structure/semantics of a certain type of object (e.g., a String can be frozen, a Hash can be frozen, c). Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuples vs Lists: Semantic difference
George Sakkis [EMAIL PROTECTED] writes: On Feb 28, 10:45 pm, Ben Finney wrote: Tuples are intended for use as heterogeneous data structures [...] Lists are intended for use as homogeneous sequences [...] Nice, that's a good summary of the straw man arguments about the true distinction between tuples and lists. I'm not sure why you say it's a straw man argument. I'm presenting *my* understanding of a position that I also share, in order to defend it; a straw man argument is a misrepresentation of *another party's* position for the purpose of appearing to attack that party's position. http://www.fallacyfiles.org/strawman.html Whose position have I misrepresented and attacked? Now can you please explain why an heterogeneous data structure: 1) does not support __setitem__, changing the value of an existing item from 3 to 4, In the case of a tuple, because the value is conceptually the entire tuple. To change one of its items would be to create a new value -- so that's what is supported. 2) supports iteration over its (heterogeneneous) elements, but not an index() method An index() method would imply that the index of an item has some meaning, such that extracting a single item is meaningful. Since a tuple represents a single conceptual structural value, to extract one item is something to be done at the same time as extracting all the others. 3) why using indices rather than names for implied semantics is a good idea anyway. You've already shown that one *doesn't* use an index for accessing items in a tuple. As for addition/removal/insertion of elements not making sense for a heterogeneous data structure, have you heard of database schema change ? A database schema change is not an operation one performs with the expectation that the tuples will remain the same. Thus, one would expect to discard the old tuples as obsolete and retrieve them from the relation again, getting new tuples. Heterogeneous data structures are well known for several decades now; they are commonly spelled records though, not tuples, and have a more reasonable API to support their semantics. Python doesn't natively support relational schema operations. It does natively support tuples. I never professed that the two were the same, and don't accept that they should be. -- \ I have never made but one prayer to God, a very short one: 'O | `\ Lord, make my enemies ridiculous!' And God granted it. -- | _o__) Voltaire | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Tuples vs Lists: Semantic difference (was: Extract String From Enclosing Tuple)
Bjoern Schliessmann [EMAIL PROTECTED] writes: Ben Finney wrote: A tuple implies a meaning associated with each position in the sequence (like a record with a positional meaning for each field), a list implies the opposite (a sequence with order but not meaning associated with each position). Explain. Well, since you ask so politely :-) I know tuples as immutable lists ... That's a common misconception. Tuples are intended for use as heterogeneous data structures: every index in the sequence *means* something, a semantic meaning applied to the item at that index. It's for this reason that a tuple is immutable: removing items, inserting them in the middle, etc. would imply that the index doesn't have semantic meaning for the structure, which is not true. Lists are intended for use as homogeneous sequences: not that every value is of the same type, but that a particular index in the sequence doesn't *mean* anything about the semantic interpretation of the item at that position. It's for this reason that a list is mutable: since the index of an item has no semantic meaning, inserting new items or removing them from anywhere in the sequence doesn't alter the meaning of the structure. James Tauber explains further: URL:http://jtauber.com/blog/2006/04/15/python_tuples_are_not_just_constant_lists -- \ You can be a victor without having victims. -- Harriet Woods | `\ | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuples vs Lists: Semantic difference (was: Extract String From Enclosing Tuple)
On Feb 28, 10:45 pm, Ben Finney [EMAIL PROTECTED] wrote: Bjoern Schliessmann [EMAIL PROTECTED] writes: I know tuples as immutable lists ... That's a common misconception. And this catch phrase, that's a common misconception, is a common aping of the BDFL's take on this. As several long threads have shown, it is a highly controversial topic and claiming that one side has misconceived it doesn't make it more true than a Catholic claiming that Protestants are misconceived about the True Christianity or vice versa. Tuples are intended for use as heterogeneous data structures: every index in the sequence *means* something, a semantic meaning applied to the item at that index. It's for this reason that a tuple is immutable: removing items, inserting them in the middle, etc. would imply that the index doesn't have semantic meaning for the structure, which is not true. Lists are intended for use as homogeneous sequences: not that every value is of the same type, but that a particular index in the sequence doesn't *mean* anything about the semantic interpretation of the item at that position. It's for this reason that a list is mutable: since the index of an item has no semantic meaning, inserting new items or removing them from anywhere in the sequence doesn't alter the meaning of the structure. James Tauber explains further: URL:http://jtauber.com/blog/2006/04/15/python_tuples_are_not_just_constan... Nice, that's a good summary of the straw man arguments about the true distinction between tuples and lists. Now can you please explain why an heterogeneous data structure: 1) does not support __setitem__, changing the value of an existing item from 3 to 4, 2) supports iteration over its (heterogeneneous) elements, but not an index() method, and 3) why using indices rather than names for implied semantics is a good idea anyway. As for addition/removal/insertion of elements not making sense for a heterogeneous data structure, have you heard of database schema change ? Heterogeneous data structures are well known for several decades now; they are commonly spelled records though, not tuples, and have a more reasonable API to support their semantics. George -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
Op 2005-01-11, Reinhold Birkenfeld schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Op 2005-01-10, Bruno Desthuilliers schreef [EMAIL PROTECTED]: Antoon Pardon a écrit : Op 2005-01-08, Bruno Desthuilliers schreef [EMAIL PROTECTED]: worzel a écrit : I get what the difference is between a tuple and a list, but why would I ever care about the tuple's immuutability? Because, from a purely pratical POV, only an immutable object can be used as kay in a dict. my-bad s/kay/key/ /my-bad This is not true. Chapter and verse, please ? I don't need chapter and verse. I have already used mutable objects as keys and it works just fine. class hlst(list): def __hash__(self): sum = 0 for el in self: sum += hash(el) return sum % 0x3777 Given this hash function, how do you handle changed keys? I don't change keys. The fact that I like to use a mutable as a key doesn't imply I want to mutate a key. And if you can't access the element when it's changed, what is the advantage over using tuples? The debate over what the adavantage is of tuples over lists or vice versa as keys in dictionaries is IMO misguided. Whether I use a list or a tuple is not guided by whether they are going to be used as a key or not, but how in general the data is to be manipulated. If the typical manipulations are modifications of an existing object, I use a list, if the typical manipulation creates new objects out of old ones I use a tuple. If I then find that I need this object as a key, I just provide a hash so that I can use this object as a key in a straight forward manner, without the hassle of converting to and from a tuple all the time. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
Op 2005-01-10, Bruno Desthuilliers schreef [EMAIL PROTECTED]: Antoon Pardon a écrit : Op 2005-01-08, Bruno Desthuilliers schreef [EMAIL PROTECTED]: worzel a écrit : I get what the difference is between a tuple and a list, but why would I ever care about the tuple's immuutability? Because, from a purely pratical POV, only an immutable object can be used as kay in a dict. my-bad s/kay/key/ /my-bad This is not true. Chapter and verse, please ? I don't need chapter and verse. I have already used mutable objects as keys and it works just fine. class hlst(list): def __hash__(self): sum = 0 for el in self: sum += hash(el) return sum % 0x3777 lst = hlst([3,5,7]) lst [3, 5, 7] lst[0] = 12 lst [12, 5, 7] d = {} d[lst] = 4 So you can use tuples for 'composed key'. lists can be so used too. Just provide a hash. Please show us an example, and let's see how useful and handy this is from a purely practical POV ?-) It is handy from a pratical point of view when most operations you do on your data are the equivalent of appending, deleting and changing one element. Simulating these with tuples will cost you more than putting a copy of your list in the dictionary as a precaution against accidently mutating a key. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
Steve Holden wrote: worzel wrote: 'Two-Pull' it is then, thanks. Well, it might be Two-Pull in American, but in English it's tyoopl -- NOT choopl (blearch!). I've also heard people say tuppl. So, basically, say whatever you want. Language is about communication :-) Or just write it down and don't say the word at all (-: regards, Gerrit, who actually says tpel. -- Weather in Lulea / Kallax, Sweden 10/01 10:20: -12.0C wind 0.0 m/s None (34 m above NAP) -- In the councils of government, we must guard against the acquisition of unwarranted influence, whether sought or unsought, by the military-industrial complex. The potential for the disastrous rise of misplaced power exists and will persist. -Dwight David Eisenhower, January 17, 1961 -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
Op 2005-01-08, Bruno Desthuilliers schreef [EMAIL PROTECTED]: worzel a écrit : I get what the difference is between a tuple and a list, but why would I ever care about the tuple's immuutability? Because, from a purely pratical POV, only an immutable object can be used as kay in a dict. This is not true. So you can use tuples for 'composed key'. lists can be so used too. Just provide a hash. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
Antoon Pardon a écrit : Op 2005-01-08, Bruno Desthuilliers schreef [EMAIL PROTECTED]: worzel a écrit : I get what the difference is between a tuple and a list, but why would I ever care about the tuple's immuutability? Because, from a purely pratical POV, only an immutable object can be used as kay in a dict. my-bad s/kay/key/ /my-bad This is not true. Chapter and verse, please ? So you can use tuples for 'composed key'. lists can be so used too. Just provide a hash. Please show us an example, and let's see how useful and handy this is from a purely practical POV ?-) Bruno -- http://mail.python.org/mailman/listinfo/python-list
tuples vs lists
I get what the difference is between a tuple and a list, but why would I ever care about the tuple's immuutability? Also, do you say 'too-ple' or 'chu-ple' - if you get my drift. (tomato or tomato kind of thing) TIA -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
worzel a écrit : I get what the difference is between a tuple and a list, but why would I ever care about the tuple's immuutability? Because, from a purely pratical POV, only an immutable object can be used as kay in a dict. So you can use tuples for 'composed key'. Bruno -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
worzel wrote: I get what the difference is between a tuple and a list, but why would I ever care about the tuple's immuutability? Mainly for security and speed. Many library functions return info by returning a reference to an internally held tuple, and could be damaged / compromised / corrupted if that internal data was modified by malicious code. If tuples were mutable (lists) then it would be necessary to return a copy instead. Also, do you say 'too-ple' or 'chu-ple' - if you get my drift. (tomato or tomato kind of thing) Try 'Two-pull'. Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
Cheers - thanks for the feedback guys - pretty much answers the question for me. 'Two-Pull' it is then, thanks. Steve Horsley [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] worzel wrote: I get what the difference is between a tuple and a list, but why would I ever care about the tuple's immuutability? Mainly for security and speed. Many library functions return info by returning a reference to an internally held tuple, and could be damaged / compromised / corrupted if that internal data was modified by malicious code. If tuples were mutable (lists) then it would be necessary to return a copy instead. Also, do you say 'too-ple' or 'chu-ple' - if you get my drift. (tomato or tomato kind of thing) Try 'Two-pull'. Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
worzel wrote: Cheers - thanks for the feedback guys - pretty much answers the question for me. 'Two-Pull' it is then, thanks. Well, it might be Two-Pull in American, but in English it's tyoopl -- NOT choopl (blearch!). I've also heard people say tuppl. So, basically, say whatever you want. Language is about communication :-) you-say-tomato-ly y'rs - steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
Steve Holden wrote: Well, it might be Two-Pull in American, but in English it's tyoopl -- NOT choopl (blearch!). I've also heard people say tuppl. Probably the same ones who attend Tuppl-ware parties. --Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
yes, tyoopl - thats what I meant by 'choo-ple' (not v good at the phonetics) As a scouse git (though living in Australia), I would definitely say 'tyoopl'. Steve Holden [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] worzel wrote: Cheers - thanks for the feedback guys - pretty much answers the question for me. 'Two-Pull' it is then, thanks. Well, it might be Two-Pull in American, but in English it's tyoopl -- NOT choopl (blearch!). I've also heard people say tuppl. So, basically, say whatever you want. Language is about communication :-) you-say-tomato-ly y'rs - steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples vs lists
worzel wrote: I get what the difference is between a tuple and a list, but why would I ever care about the tuple's immuutability? Also, do you say 'too-ple' or 'chu-ple' - if you get my drift. (tomato or tomato kind of thing) TIA I use the Festival Speech Synthesis System to learn pronunciations sometimes. The American english voice is quite accurate. -- Sean Dolan -- http://mail.python.org/mailman/listinfo/python-list