Teddy Teddy - 1 year ago 55
Python Question

How to return index of specific pairs of values?

I need to find the index (row number) of specific pairs of value from an array. Below is example array.

A=[[357 131]
[319 171]
[229 196]
[398 135]
[242 148]

I want to know the index of [229 196] and [242 148] as their row number

3 and 5

I was trying to use

A.index ([229 196]) or A.index([229 196])

but did not work. How to get the row number of specific pairs of values?

3kt 3kt
Answer Source

You may want to take a look at the documentation regarding arrays. A should be defined this way :

>>> A=[[357,131],[319,171],[229,196],[398,135],[242,148]]

Your guess was right though, regarding how to access the index of the elements of the array :

>>> A.index([229,196])
>>> A.index([242,148])

Be careful, those return 2 and 4, and not 3 and 5 ! Indeed, the index of an array starts at 0, and not 1 ! You can check this by doing A[0].

Hope it'll be helpful.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download