FEEDBACK WANTED: Type/class unification
Markus Schaber
markus at schabi.de
Tue Aug 7 16:55:58 EDT 2001
Hi,
Jeff Shannon <jeff at ccvcorp.com> schrub:
>> With the automatic turning to 0/maxint, they even are limited to
>> non-negative integers. So it is impossible to use any form of
>> negative indexes, which sometimes would be nice when dealing with
>> coordinates.
>
> Um.... you *can* use negative values in slices:
>
>>>> mylist = [1, 2, 3, 4]
>>>> mylist[-2:-1]
> [3]
>>>> mylist [:-2]
> [1, 2]
Yes - but this means "count from the other end" instead of "go
backwards from index 0"
> What you can't have, is negative indices into a list.
And this is what I sometimes would like to have.
> Neither of
> these, however, have anything to do with the specific case being
> discussed, which is the default value used for unspecified slice
> endpoints.
Thats correct, there I wrote something different to what I thought of.
My complain was meant about the fact, that the conversion is done
before my method is called, instead of leavint this decision to my own
implementation.
> A list of lists is really not the same thing as a 2d-array, and is
> probably
> not suitable for use as a coordinate system. If you really *must* do
> so, though, and your coordinates *must* include negative values, then
> you could wrap the list of lists into a class and provide an automatic
> translation.
At least when dealing with something like a "Fungespace" (i. E. you
have small integers as indices in an array, but the offsets can get
negative) it would be useful.
I always have to use an own class for it (as there's no builtin list
with negative indices), but I can't use slicing syntax with this own
class as the negative values are automatically converted to end-value
before calling my method.
There may be other scenarios when this conversion would be useful -
imagine a double linked ring list. Then small negative values could
mean "come from the end" which is much faster then coming from the
start when the list is long.
markus
--
Defend democrathy and freedom!
More information about the Python-list
mailing list