Python script to print index of all occurrence of given element in a given list

In this program we will check that at what index an element in a list is occurring

we will take input list from the user and the element user wants to know the index of.


l=[eval(x) for x in input("enter list element ").split(',')]
element=eval(input("enter element value "))
index=0
while index<len(l):
   if l[index]==element:
      print(index,end=' ')
   index+=1   
Output:
enter list element 1,2,1,3,1,4,2,1,1
enter element value 1
0 2 4 7 8

Happy Coding!

Follow us on Instagram @programmersdoor

Join us on Telegram @programmersdoor


Please write comments if you find any bug in above code/algorithm, or find other ways to solve the same problem.

Follow Programmers Door for more.

#blog #interview #placement #learn #computer #science

4 views

        Contact Us

programmersdoor@gmail.com

  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door