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
Post a Comment