Write a Python Program to Remove the ith Occurrence of the Given Word in a List where Words can Repeat


Topic: Write a Python Program to Remove the ith Occurrence of the Given Word in a List where Words can Repeat

Solution

a=['the', 'tsai', 'python' ,'a' ,'the', 'a']
c=[]
count=0
b='a'
n=3
for i in a:
    if(i==b):
        count=count+1
        if(count!=n):
            c.append(i)
    else:
        c.append(i)
if(count==0):
    print("Item not found ")
else: 
    print("The number of repetitions is: ",count)
    print("Updated list is: ",c)
    print("The distinct elements are: ",set(a))



List all Python Programs