Try it ... it works like a charm.
Actually in your problem iteration is performed only once, even in for loop, it does not work (it does not work for me even after iter and next() ), so I tried with while , then I understand that this is an iteration game so put while in try using while 1: to start with iteration 1 , and the index method performs a linear search and stops at the first matching element. If no matching element is found, it throws a ValueError exception.
CODE
list = ['dog','cat','pizza','trump', 'computer', 'trump'] value = "trump" i = -1 try: while 1: # Start with Iteration 1 never 0 i = list.index(value, i+1) print(value,"at", i) except ValueError: # No matching item is found. pass
OUTPUT
trump at 3 trump at 5
source share