aladdin hammodi
aladdin hammodi

Reputation: 21

Python- Getting a specific information from an array

If I have this array how could I get the values of the distances?

    [ 0, { 'labels': [ 0, 0,1]  'distances' : [10.132, 10.341, 13.314 ]}] 

I mean how could I print the value 10.132

Upvotes: 0

Views: 27

Answers (1)

Ben
Ben

Reputation: 6358

You have to subscript into the array, then subscript again into the dictionary (I had to add a comma to avoid the syntax error in your dictionary, by the way):

myarray = [ 0, { 'labels': [ 0, 0,1],  'distances' : [10.132, 10.341, 13.314 ]}]

myarray[1]['distances']
Out[3]: [10.132, 10.341, 13.314]

If you want each distance, subscript again:

myarray[1]['distances'][0]
Out[4]: 10.132

If this is still isn't making sense, add a comment, and I'll expand my answer.

Upvotes: 1

Related Questions