Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views1 page

EXPERIMENT10

The document outlines an experiment to create a program that removes the i'th occurrence of a specified word from a list. The provided source code demonstrates the functionality, successfully removing the targeted occurrence of the word 'apple' from the list. The conclusion confirms the program's effectiveness in achieving its objective.

Uploaded by

Ayush Gautam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

EXPERIMENT10

The document outlines an experiment to create a program that removes the i'th occurrence of a specified word from a list. The provided source code demonstrates the functionality, successfully removing the targeted occurrence of the word 'apple' from the list. The conclusion confirms the program's effectiveness in achieving its objective.

Uploaded by

Ayush Gautam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

EXPERIMENT-10

Objective: To make a program to remove i’th occurrence of a given word.


Source code:
def remove_ith_occurrence(word_list,word_to_remove,i):
count=0
for index,word in enumerate(word_list):
if word == word_to_remove:
count+=1
if count == i:
del word_list[index]
return word_list #stop after removing ith occurrence
return word_list
words= ['apple','banana','cherry','apple','date','apple']
print(words)
word_to_remove='apple'
i=2
result= remove_ith_occurrence(words,word_to_remove,i)
print(result)
Input and output:

Conclusion: The experiment successfully developed a program to remove the i’th occurrence
of a given word from a text. The program accurately identifies and eliminates the desired
occurrence.

You might also like