Below is the code. Why is it behaving so? What is the alternative?
line2 = ["a", "b","c","d","e","f","g","a","c", "d","e","g","h",]
for x in line2:
print("X value is:", x, " and its index is:", line2.index(x))
Output is:
X value is: a and its index is: 0
X value is: b and its index is: 1
X value is: c and its index is: 2
X value is: d and its index is: 3
X value is: e and its index is: 4
X value is: f and its index is: 5
X value is: g and its index is: 6
X value is: a and its index is: 0
X value is: c and its index is: 2
X value is: d and its index is: 3
X value is: e and its index is: 4
X value is: g and its index is: 6
X value is: h and its index is: 12
Why is it not incrementing ?. How do I resolve. I need increments of index ? Instead of index do we have something like position of X