MCQs > IT & Programming > Python > Which is the best method to find the indices of all occurances of a word in a string? line = 'mary had a little lamb, little lamb, little lamb' word = 'lamb'

Python MCQs

Which of the following is the best method to find the indices of all occurances of a word in a string?

line = 'mary had a little lamb, little lamb, little lamb'

word = 'lamb'

Answer

Correct Answer: import re indices = [occurance.start() for occurance in re.finditer(word, line)]

Explanation:

Note: This Question is unanswered, help us to find answer for this one

Python Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

Python Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it