Indexes and Slices.

Magnus Lyckå magnus at thinkware.se
Fri Feb 22 13:03:52 EST 2002


>>>>st[12,2] = "hola"
>>>>
> setitem: ((12, 2), 'hola')
> 
> ## THIS was news.
> ## Commas in indexes convert the index into a tuple.
> ## So I can use more complex behaviours, like multi-
> ## dimensional indexing.


No, this is not news. It worked in 2.1 as well at
least, and I frankly don't understand what the
excitement is about.

st[12,2] is short for st[(12,2)]. You've always been
allowed to use tuples of immutable objects as keys for
dicts. Or am I missing something here?

Unless the documentation explicitly says that the
parenthesis can be skipped in this context, I would
be a bit cautious to use that feature. Previously (up
to 1.5.2?) you could (but should not) skip the parenthesis
when you added a tuple with list.append() and in
socket.connect() for instance, but that bug was removed.

Allowing bare tuples in function calls means that you can
get confused about whether the the function takes one tuple
or several parameters. Although inside [] there is really
no risk for confusion. So maybe [1,2,23] won't go away...




More information about the Python-list mailing list