Python doesn't support that syntax because it doesn't support that syntax. Short of badgering Guido van Rossum, that's the best answer you're going to get.
It's easy to add to a list
subclass, though:
class List(list):
def __getitem__(self, index):
try:
return list.__getitem__(self, index)
except TypeError:
return List(self[i] for i in index)
def __setitem__(self, index, value):
try:
return list.__setitem__(self, index, value)
except TypeError:
value = iter(value)
for i in index:
self[i] = next(value)
a = List(range(10))
a.reverse()
print(a[1, 3, 5]) # [8, 6, 4]
a[1, 3, 5] = 1, 2, 3
print(a) # [9, 1, 7, 2, 5, 3, 3, 2, 1, 0]
The __setitem__
doesn't behave well when you have more values than slots you're filling (it should probably give you an error) but that's tricky to do while also supporting generators, so, meh.
The triviality of implementing it may have bearing on the fact that it's not part of the language; the __getitem__
especially is just a simple list comprehension (or generator expression in this case) which you could just as easily write in your own code wherever you needed to do it.