An oddity in list comparison and element assignment
aleax at mac.com
Sat Jun 3 04:25:44 CEST 2006
Terry Reedy <tjreedy at udel.edu> wrote:
> <michael.f.ellis at gmail.com> wrote in message
> news:1149277242.199765.213600 at g10g2000cwb.googlegroups.com...
> > (As an aside, may I point out that Python In A Nutshell states on page
> > 46 "The result of S*n or n*S is the concatenation of n copies of S".
> It would be more exact to say that S*n is  extended with S n times,
> which makes it clear that 0*S == S*0 ==  and which avoids the apparently
> misleading word 'copy'. I presume the C implementation is the equivalent
Considering that the very next (and final) sentence in that same
paragraph is "If n is zero or less than zero, the result is an empty
sequence of the same type as S", I don't think there's anything
misleading in the quoted sentence. Moreover, since the paragraph is
about sequences, not just lists, it *WOULD* be horribly wrong to use the
phrasing you suggest: "bah!"*3 is NOT a list, it's EXACTLY the
concatenation of three copies of that string -- no more, no less.
> Or one could say that the result *is the same as* (not *is*) the
I find this distinction, in this context, to be empty padding, with zero
added value on ANY plane -- including the plane of "pedantry";-).
> concatenation of n *shallow* copies of S. 'Shallow' means that each copy
I do not think it would be good to introduce the concept of "shallow" at
a point in the text which is talking about ALL sequences -- including
ones, such as strings, for which it just does not apply.
But, thanks for the suggestions, anyway!
More information about the Python-list