Steven D'Aprano wrote:
Here's a less verbose version which passes your test cases:
def inslice(index, slc, len):
"""Return True if index would be part of slice slc of a
sequence of length len, otherwise return False.
"""
start, stop, stride = slc.indices(len)
if stride < 0:
On Sat, 03 Jan 2009 14:53:12 -0800, Bryan Olson wrote about testing
whether or not an index is in a slice:
> I'm leaning towards mmanns' idea that this should be built in.
What's the use-case for it?
> Handling
> all the cases is remarkably tricky. Here's a verbose version, with a
> little t
On Jan 3, 8:53 pm, Bryan Olson wrote:
> If we add a parameter for the length of the list to which the slice is
> applied, then inslice() is well-defined.
Cool!
> I thought it would easy to write,
Heh, I gave up on the example I mentioned above :)
> but that was hours ago when I knew
> less abo
ajaksu wrote:
On Jan 1, 4:12 pm, mma...@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 f
On Thu, 1 Jan 2009 11:34:53 -0800 (PST)
ajaksu wrote:
> http://article.gmane.org/gmane.comp.python.python-3000.devel/8732
I will build upon this code.
Thanks for your help
Martin
--
http://mail.python.org/mailman/listinfo/python-list
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, p
On Jan 1, 4:12 pm, mma...@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 fle
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?
M
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?
M