A multi-dimensional array is an array of arrays.  For example:

x = [[“a”,”b”,”c”],[“d”,”e”,”f”],[“g”,”h”,”i”]]

If you wanted to list all the values in the entire collection you could do this with…

Ruby

s.each do |sub|
    sub.each do |y|
        puts y
    end
end

Python

for i in x:
    for y in i:
        print(y)

Individual Values

Python and Ruby are similar here.  You can find a specific value with a syntax like:

Ruby

  puts x[0][1]

>> b
b is returned as it’s the value in index 0, sub index 1

Python

  print(x[0][1])

>> b

 

Leave a Reply

Your email address will not be published. Required fields are marked *