4 ms·
No, it doesn't, it prints ['D', 'C']. I agree that it should be ['C', 'B'] - the way that Python handles negative `step` values is wrong.
by pansa2 2y ago
No, it doesn't, it prints ['D', 'C'].
I agree that it should be ['C', 'B'] - the way that Python handles negative `step` values is wrong.
- Ukv 2y agoI don't think it's "wrong" per se - it's zero-based indexing and ranges are consistently inclusive of start, exclusive of end. But, it breaks the "fence-post" mental model that some people use, and is less intuitive than MatLab's indexing approach IMO.
- pansa2 2y ago> I don't think it's "wrong" per se I do. I think it only makes sense for ranges to be inclusive at the lower end and exclusive at the higher end. A slice with a negative step `-n` should contain the same elements as the same slice as with step `n`, just reversed.