Possible improvement to slice opperations.
Patrick Maupin
pmaupin at gmail.com
Tue Sep 6 09:34:02 EDT 2005
Ron Adam wrote:
>> This should never fail with an assertion error. You will note that it
>> shows that, for non-negative start and end values, slicing behavior is
>> _exactly_ like extended range behavior.
> Yes, and it passes for negative start and end values as well.
Umm, no:
.>> for stride in [-3, -2, -1, 1, 2, 3]:
... for start in range(-1,len(L)):
... for end in range(-1,len(L)):
... P = L[start:end:stride]
... Q = [L[i] for i in range(start, end, stride)]
... assert P==Q, [start, end, stride, P, Q]
...
Traceback (most recent call last):
File "<stdin>", line 6, in ?
AssertionError: [-1, 0, -3, [9, 6, 3], []]
> Thanks again, this pretty much explains why slices opperate the
> way they do. And it explains why the edge case's happen as well I think.
You're welcome.
Regards,
Pat
More information about the Python-list
mailing list