Is there any way in python to use a tuple as the indices for a slice? The following is not valid:
>>> a = range(20)
>>> b = (5, 12) # my slice indices
>>> a[b] # not valid
>>> a[slice(b)] # not valid
>>> a[b[0]:b[1]] # is an awkward syntax
[5, 6, 7, 8, 9, 10, 11]
>>> b1, b2 = b
>>> a[b1:b2] # looks a bit cleaner
[5, 6, 7, 8, 9, 10, 11]
似乎像一个合理的幻灯.,所以我感到惊讶的是,我可以这样做。