: for displaying all elements in a multidimensional array in python 3.1.
- by Leif Andersen
I have a multidimensional array in python like:
arr = [['foo', 1], ['bar',2]]
Now, if I want to print out everything in the array, I could do:
print(arr[:][:])
Or I could also just do print(arr). However, If I only wanted to print out the first element of each box (for arr, that would be 'foo', 'bar'), I would imagine I would do something like:
print(arr[:][0])
however, that just prints out the first data blog (['foo', 1]), also, I tried reversing it (just in case):
print(arr[0][:])
and I got the same thing. So, is there anyway that I can get it to print the first element in each tuple (other than:
for tuple in arr:
print(tuple[0])
)? Thanks.