: for displaying all elements in a multidimensional array in python 3.1.

Posted by Leif Andersen on Stack Overflow See other posts from Stack Overflow or by Leif Andersen
Published on 2010-06-02T19:58:10Z Indexed on 2010/06/02 20:04 UTC
Read the original article Hit count: 156

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about python

Related posts about arrays