On Sep 27, 2006, at 12:23 PM, Vince Teachout wrote:

What I recall being frustrating was THINKING I understood slicing, and then trying to predict what the result of a particular slice would be. Something along the lines of "foobar[1,2] should give me the letter 'A'", and then getting back a P, or a OOBAR or something. (that's widely paraphrasing from something I recall from several months ago, not a real example)

You might be tripping over one of the other differences between Fox and Python: one-based vs. zero-based indexing. The first element in a Fox array is referenced as myArray[1], whereas in Python it is myList [0].

Here's a quick example using a string, which internally is a list of characters. Let's say I have:

x = "Vince Teachout"

        I can reference any single character using its zero-based position:

x[0] => "V"
x[3] => "c"

What's really cool is relative indexes. For example, let's say I want the last character of the string:

x[-1] = "t"
x[-4] = "h"

I can reference any range of characters via a slice, where the first number is the starting element's index, and the second is the index of the element that the slice will go up to, but *not* include. So I would have:

x[1:4] => start at element 1 and go up to but not include element 4 => "inc" x[:5] => start at element zero (implied) and go up but not include element 5 => "Vince"

        Relative indexes also work with slices:

x[-7:-3] => "each"
x[-7:] => "eachout"

There are so many possibilities, including steps, reversing, etc., but this should give you the basics.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to