How to find the position of an element in a list , in Python?

Viewed 93060
for s in stocks_list:
    print s

how do I know what "position" s is in? So that I can do stocks_list[4] in the future?

4 Answers

The position is called by stocks_list.index(s), for example:

for s in stocks_list:
    print(stocks_list.index(s))
Related