Ooops, Forgot "reply all" last time -- here it is again.
On Wed, Apr 23, 2014 at 3:17 PM, Chris Barker <chris.bar...@noaa.gov> wrote: > On Mon, Apr 21, 2014 at 11:39 PM, Raymond Hettinger < > raymond.hettin...@gmail.com> wrote: > >> In fact, the distinction is extrinsic to their implementations. It is >> only important >> because the rest of the language tends to treat them differently. For >> example, >> you could store ['raymond', 'red'] as a list or as a tuple ('raymond', >> 'red'), but you >> wouldn't be punished until later when you tried: >> >> 'I think %s likes %s' % container # str.__mod__ treats lists and >> tuples differently >> > > I've been bitten by that a lot -- I always wondered why that didn't work > with any sequence. like "tuple unpacking", which is really sequence > unpacking: > > x, y = [3,4] > > But anyway, when I teach Python, I do struggle with this issue -- I tend > to give the explanation of "structs" vs. "homogenous sequences", but I feel > like I am repeating a party line, rather than anything useful. What I do > is: > > If it needs to be immutable (dict key), then use a tuple > If it needs to be mutable, then use a list > > Otherwise, you can use either, but I tend to use a tuple for small things > I don't need to mutate, regardless of whether they are homogenous or not -- > it makes me feel better to get the perception of a *tiny* bit more > efficiency. > > And sometimes you want to mutate small collections of inhomogeneous values > (C sructs are mutable, after all). > > So I don't think this needs to be codified this in the docs anywhere. > > >> Likewise, there seems to be wide-spread confusion about make makes an >> object immutable. People seem to miss that ints, tuples, None and str are >> immutable only because they lack any mutating methods, >> > > not sure your point here -- that under the hood one could mutate them with > C code? > -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.go <chris.bar...@noaa.gov>
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com