On Fri, 21 Apr 2006 23:33:07 +0200 Georg Dahn <[EMAIL PROTECTED]> wrote:
Hi Georg, > No: Let's assume, that you have an empty list a. Then M in a[M:N] is > always out of bounds, which should produce an error. Analogously, if a > is not empty, but M > len(a), an error should be produced, too. (BTW, is > an error produced in this case at the moment?) > > And my opinion is, that an error should be produced, too, if N > len(a) > and a is not 0. A programmer should take care of the bounds. If an index > is out of bounds, I consider it as wrong not to produce an error. But > this is, as I have said already, just my humble opinion. Yes, my point was just that it should be consistent. Either, N > len(a) should always generate an error or it shouldn't any of the time, even if len(a) happens to be 0. It's the counterintutive mixing of both policies that I think is suboptimal. > The following situation would be different: If M were the starting point > and N the number of items, one could say, that a[M:N] should return at > most N items starting with the M'th item. Having used python a lot, i actually quite enjoy being given the freedom to use out of bound ranges and simply get an empty list in return. I handle the out of bound case by testing or processing an empty list after the fact. It tends to lead to somewhat easier to read code in some cases. That said, having to test the ranges before every slice is workable, but it should be consistent. Cheers, Sean