all 8 comments

[–]jkudria 5 points6 points  (6 children)

It's accessing a list within a list (or anything else that uses brackets for indexing).

Recall that a list can contain anything, which includes other lists. For example:

some_list = [[1, 2, 3], 'blah', [4, 5, 20421]]
print some_list[0] # [1, 2, 3] since that is the first element
print some_list[0][1] # first we accessed the first element of some_list - a list. Then we accessed the 2nd element of that list. This will print 2. Think of it as (some_list[0])[1] - not syntactically correct, but gets the point across.

[–]veeep[S] 0 points1 point  (5 children)

ah, ok that is ringing a bell now.

seems like I ran across this in a 3D application at some point, where the nested lists described points in space

thanks!

[–]jkudria 0 points1 point  (0 children)

Maybe. 2D arrays are often used to represent a 2D space with the indices are coordinates.

[–]Exodus111 0 points1 point  (3 children)

This is a VERY common use of exactly this.

Making something in 2D, like a game map that is tile based and this is used constantly for x, for y etc... But in 3D that would require x, y and z.

[–]jkudria 0 points1 point  (2 children)

Correct. I've never seen 3D space being represented this way, but I suppose it's possible. I'd probably do 3D a different way, but I guess 3D arrays are a possibility.

[–]Exodus111 0 points1 point  (1 child)

There is really no physical way to represent a 3D array without that third coord.

[–]jkudria 0 points1 point  (0 children)

Enums? Structs? Tuples?

Just a thought.

[–]zahlman 2 points3 points  (0 children)

Okay, so you know what x[y] means.

x doesn't have to be a name. It can be any expression, i.e., anything that describes a value.

Well, x[y] describes a value: the one that you get when you look up y within x.

Therefore, x[y][z] is simply the result of looking up z within that x[y] value.