Ask Your Question

Revision history [back]

First, your question adds an useless level of complexity, since everyting happens within A[0], so let me first refice it:

sage: B = [99999,99999,1,99999]
sage: B.index(B[0])
0
sage: B.index(B[1])
0
sage: B.index(B[2])
2
sage: B.index(B[3])
0

You can check the document of the index method of lists as follows:

sage: B.index?

As you can see, this method B.index(x) returns the smallest index i such that B[i]=x (when it exists, otherwise it raises a ValueError).

In your case, there are 3 indices i for which B[i]=99999, namely 0,1,3. The smallest of them is 0, hence B.index(99999) will return 0. The fact that 99999 was provided by B[0], B[1] or B[3] does not matter.

First, your question adds an useless level of complexity, since everyting happens within A[0], so let me first refice it:

sage: B = [99999,99999,1,99999]
sage: B.index(B[0])
0
sage: B.index(B[1])
0
sage: B.index(B[2])
2
sage: B.index(B[3])
0

You can check the document of the index method of lists as follows:

sage: B.index?

As you can see, this method B.index(x) returns the smallest index i such that B[i]=x (when it exists, otherwise it raises a ValueError).

In your case, there are 3 indices i for which B[i]=99999, namely 0,1,3. The smallest of them is 0, hence B.index(99999) will return 0. The fact that 99999 was provided by B[0], B[1] or B[3] does not matter.

Note that ths question is only about the Python language, not Sage. Hence you might find tons of explanations about this on the web.

First, your question adds an useless level of complexity, complexity, since everyting everything happens within A[0], so let me first refice reduce it:

sage: B = [99999,99999,1,99999]
[9, 9, 1, 9]
sage: B.index(B[0])
0
sage: B.index(B[1])
0
sage: B.index(B[2])
2
sage: B.index(B[3])
0

You can check the document documentation of the index method of lists as follows:

sage: B.index?

As you can see, this method B.index(x) returns the smallest smallest index i such that B[i]=x (when it exists, otherwise it raises a ValueError).

In your our case, there are 3 three indices i for which B[i]=99999B[i] equals 9, namely 0,1,3. 0, 1, 3. The smallest of them is 0, hence B.index(99999)B.index(9) will return 0. . The fact that 999999 was provided by B[0], B[1] or B[3] does not matter.

Note that ths this question is only about the Python language, not Sage. Sage. Hence you might find tons of explanations about this on the web.

First, your question adds an a useless level of complexity, since everything happens within A[0], so let me first reduce it:

sage: B = [9, 9, 1, 9]
sage: B.index(B[0])
0
sage: B.index(B[1])
0
sage: B.index(B[2])
2
sage: B.index(B[3])
0

You can check the documentation of the index method of lists as follows:

sage: B.index?

As you can see, this method B.index(x) returns the smallest index i such that B[i]=x (when it exists, otherwise it raises a ValueError).

In our case, there are three indices i for which B[i] equals 9, namely 0, 1, 3. The smallest of them is 0, hence B.index(9) will return 0. The fact that 9 was provided by B[0], B[1] or B[3] does not matter.

Note that this question is only about the Python language, not Sage. Hence you might find tons of explanations about this on the web.