DEV Community

Discussion on: Python for JavaScript Developers

cben profile image
Beni Cherniavsky-Paskin

Correction for Lists section:

a_list[2, -2]

doesn't work.
It's same as:

index = (2, -2)  # a tuple

which gives "TypeError: list indices must be integers or slices, not tuple".

Some custom list-like objects, notably NumPy arrays, do support extracting multiple values for multiple indexes. (Except they do this given a list of indixes, as they already interpret tuples for multi-dimensional indexing.)
Anyway, it's not a builtin feature of the language.