0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@aladdinhammodi If it helped, could you please accept it? I'm gunning for points here :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.