top of page

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

Writer's picture: Priyanshu KanadePriyanshu Kanade

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.

4 views0 comments

Recent Posts

See All

Comments


bottom of page