Python: Find all adverbs and their positions in a given sentence
Python Regular Expression: Exercise-46 with Solution
Write a Python program to find all adverbs and their positions in a given sentence.
Sample Solution:
Python Code:
import re
text = "Clearly, he has no excuse for such behavior."
for m in re.finditer(r"\w+ly", text):
print('%d-%d: %s' % (m.start(), m.end(), m.group(0)))
Sample Output:
0-7: Clearly
Pictorial Presentation:
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to remove the ANSI escape sequences from a string.
Next: Write a Python program to split a string with multiple delimiters.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/re/python-re-exercise-46.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics