getting index of element in list (python) -


didn't understand why getting index of elements in list works differnt in next examples:

list = [1, 1, 1, 4]  print list.index(list[3])  

returns expected 3 index fourth element in list

but

list = [1, 1, 1, 1]  print list.index(list[3])  

unexpectedly returns 0.

what difference? it's python 3.3

list.index(x) returns index of first match. in first case first match @ index 3 i.e., 4 @ index 3, while in second case first match @ index 0 i.e, 1 @ index 0. 1 @ indices 1,2 , 3.


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -