On Jan 1, 12:12 pm, mma...@gmx.net wrote: > Hi > > 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 would like to use the batteries if possible. > However, I looked in the docs, pypi and in Usenet without luck. > > Does anyone have a solution? > > Martin
Untested: if slice.end< 0: slice.end= len( obj )- slice.end+ 1 if slice.step< 0 and slice.start<= target< slice.end: return True if slice.step> 0 and slice.start>= target> slice.end: return True return False -- http://mail.python.org/mailman/listinfo/python-list