Consistency in Python

Hendrik van Rooyen mail at microcorp.co.za
Fri Aug 25 04:38:16 EDT 2006


Hi,

for S where S is a Standard Python type:
    The slice notation S[n] returns either:
        The n'th element of S, or
        The value of the dictionary entry whose key is n.

This is beautiful because as a programmer you don't have to worry what S is...
(and as an aside - This consistency has already saved my butt when I thought I
was working with a string that turned out to be a tuple instead - and still
worked perfectly as expected...)

Now consider what you have to do to add an element to S...
(where "add" is used in its meaning of increasing the size of a set, and not 1 +
1 = 2)

There seems to be no common methods such as-
    "prepend" - for adding something to the beginning
    "append" - for adding something to the end
    "insert[j]" - for adding something somewhere in the middle

Or have I missed something ?

Is there a reason for this lack - or is it simply that the language has "just
growed" ?

Are there any plans afoot to do this kind of tidying up in the places where it
makes sense?

BTW - I understand that some things are immutable - but that is an
implementation detail, not a language issue. - the fact that you get the name S
bound to a new object is irrelevant to a discussion about how you tell the
interpreter to do something...

Any other thoughts - such as making a kind of opposite to del instead ?

- Hendrik





More information about the Python-list mailing list