Re: Negative array indicies and slice()

Discussion in 'Python' started by Mark Lawrence, Oct 29, 2012.

  1. On 29/10/2012 02:31, Andrew Robinson wrote:
    > Ok, hopefully this is better. I love my own e-mail editor...
    >
    > I can see that the slice() function can pass in arbitrary arguments.
    > I'm not sure for lists, which is what the range is applied to, why an
    > argument like "a" would be part of a slice.
    > I *really* don't see what the advantage of a slice class is over a mere
    > list in the order of start, stop, step eg: [ 1,4,9 ]
    >
    > In a dictionary, where "a" could be a key -- I wasn't aware that there
    > was a defined order that the idea of slice could apply to.
    >
    > When I look at the documentation,
    > http://www.python.org/doc//current/c-api/slice
    >
    > The only thing that slice has which is special, is that the the length
    > of the sequence can be given -- and the start and stop index are either
    > trimmed or an error (exception???) is thrown.
    >
    > Where is the information on the more general case of slice()? :-\
    >
    > I am thinking, can one use the 'super' type of access, to override --
    > within the list object itself -- the __getitem__ method, and after
    > pre-processing -- call the shadowed method with the modified
    > parameters? That would allow me to use the normal a[-4:6] notation,
    > without having to write a wrapper class that must be explicitly called.
    >
    > I'm thinking something like,
    >
    > PyListObject.__getitem__= lambda self, slice: ....
    >
    > --Andrew.
    >


    I suggest that you go back and read the tutorial about slicing. I say
    this because we've started with negative array indicies and slice() (but
    Python arrays haven't been mentioned :), then moved onto (x)range and
    now lists, dictionaries and the C API for slices.

    An alternative is to tell us precisely what you're trying to achieve.
    The odds are that there's a simple answer waiting in the wings for a
    simple question.

    --
    Cheers.

    Mark Lawrence.
    Mark Lawrence, Oct 29, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    72
    Views:
    746
    88888 Dihedral
    Nov 2, 2012
  2. Andrew Robinson

    Re: Negative array indicies and slice()

    Andrew Robinson, Oct 29, 2012, in forum: Python
    Replies:
    0
    Views:
    117
    Andrew Robinson
    Oct 29, 2012
  3. Ethan Furman

    Re: Negative array indicies and slice()

    Ethan Furman, Oct 30, 2012, in forum: Python
    Replies:
    0
    Views:
    148
    Ethan Furman
    Oct 30, 2012
  4. Dennis Lee Bieber

    Re: Negative array indicies and slice()

    Dennis Lee Bieber, Oct 31, 2012, in forum: Python
    Replies:
    0
    Views:
    142
    Dennis Lee Bieber
    Oct 31, 2012
  5. Ian Kelly
    Replies:
    0
    Views:
    188
    Ian Kelly
    Oct 31, 2012
Loading...

Share This Page