for i,k in enumerate(ls):
if k == 3:
ls.insert(i+1,"example")
break
The above code iterates through a list ls and finds the first element that equals to 3 and inserts "example" after that element and stops. While the above code can be written as,
ls.insert(ls.index(3)+1,"example")
What is the most efficient way to write a program to enter a element after the first element that passes a condition such as,
if k > 3:
or
if isPrime(k):