Testing if an index is in a slice
ajaksu
ajaksu at gmail.com
Thu Jan 1 14:34:53 EST 2009
On Jan 1, 4:12 pm, mma... at gmx.net wrote:
> I would like to check if an index is in a slice or not without
> iterating over the slice.
>
> Something like:
>
> >>> isinslice(36, slice(None, 34, -1))
>
> True
I think it'd be feasible for slices that can be mapped to ranges[1],
but slices are more flexible than that.
What would the answer be for:
>>> isinslice(36, slice(0, -1, 1))
?
This shows the issue:
>>> sli = slice(0, -1, 1)
>>> range(4)[sli]
[0, 1, 2]
>>> range(10)[sli]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
HTH,
Daniel
[1]
http://article.gmane.org/gmane.comp.python.python-3000.devel/8732
More information about the Python-list
mailing list